How to store data in share preferences in android

Share Preferences are used for storing some data, like font size, background color are array data. Its also store float , integer, string and Boolean values. Following are the example of Share Preference read and writing.
private SharedPreferences myPrefs;
private SharedPreferences.Editor editor;
/////////////////////////// object initialization
  myPrefs = this.getSharedPreferences("myPrefs", MODE_WORLD_READABLE);
         editor=myPrefs.edit(); 
////////////// store data in string value
 editor.putString("value", "android hello word programming");
   editor.commit();
//// read the store data from string value
 myPrefs = this.getSharedPreferences("myPrefs", MODE_WORLD_READABLE);
             String aString=myPrefs.getString("value", "not retrieved");
             Toast.makeText(getApplicationContext(), "data.."+aString, Toast.LENGTH_LONG).show();
           

Post a Comment

0 Comments