Posts

Showing posts from September, 2015

Android - Shared Preferences Tutorial

Shared Preferences Tutorial 1) Shared Preferences allow you to save and retrieve data in the form of key,value pair. 2) You cannot share preferences outside of the package. 3) Preferences are stored as groups of key/value pairs. Creating shared preferences  SharedPreferences pref = getSharedPreferences(“MyPreferences”, Context.MODE_PRIVATE); - The first parameter is the key and the second parameter is the MODE. - You can save something in the sharedpreferences by using SharedPreferences.Editor class. SharedPreference.Editor editor = pref.edit(); SharedPreferences.Editor Methods : 1) clear() :  It will remove all values from the editor. 2) remove(String key) :  It will remove the value whose key has been passed as a parameter. 3) putString(String key, String value) :  It will save a String value in a preference editor. 4) putLong(String key, long value) :  It will save a long value in a preference editor. 5) putInt(String key, int value) :  It will save