Monday, 25 February 2013

Android Shared Preferences(Store value in the form of (key,value) pairs privately)

//setting the value in the Shared Preferences

  SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
  SharedPreferences.Editor editor = preferences.edit();
  editor.putString("myName","ABC");
  editor.commit();
 
 
//getting the value from the Shared Preferences


  SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
  String name = preferences.getString("myName","");
  Log.d("My Name=",name);
 
 
 
Enjoy one of the basic and simple one. 

No comments:

Post a Comment