Saving information using Shared Preference in Android?
How to Read the Preference?
1) Get the sharedpreference for the preference name
ex) SharedPreferences prefs = ctx.getSharedPreferences(prefName,0);
2) Get all the key value pairs from the preference
ex) Map data = prefs.getAll();
3) Iterate through the map and you can retrive the data for your key.
How to Save the Preference?
1) Get the sharedpreference editor for the preference
SharedPreferences.Editor prefs =
context.getSharedPreferences(getPrefname(), 0).edit();
2) add the key and value to the preference
prefs.putString(newkey, value);
3) Commit your changes
prefs.commit();
How to remove preference?
1)Do all the above steps to get the editor and
then use the remove method
to remove the preference.
prefs.remove(newkey);