Thursday, January 7, 2016

SharedPreferences in Android [ put string and get string ]

PUT
private SharedPreferences sharedPreferences;
sharedPreferences.edit()
        .putString("KEY_NAME", name)
        .apply();


GET
String NameURL= getPref("KEY_NAME", getContext());

public static String getPref(String key, Context context) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); 
  return preferences.getString(key, null);
 
 
 
Resources: 
https://medium.com/google-developers/sharedpreferences-is-your-answer-to-simple-storage-a7c8499ea8ff#.7eoyjrjgi