android studio sharedpreferences example
Example 1: android sharedpreferences
SharedPreferences sharedPref = getSharedPreferences(PREFERENCES_FILENAME, MODE_PRIVATE);
String value = sharedPref.getString(PREFERENCE_KEY, null);
sharedPref.edit()
.putString(PREFERENCE_KEY, value)
.apply();
Example 2: android sharedpreferences
SharedPreferences sharedPref = getSharedPreferences("name", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("key", "Value");
editor.commit();
Example 3: get preference value android
boolean mBoolean = PreferenceManager.getDefaultSharedPreferences(yourContext).getBoolean(key, defaultValue);
Example 4: set preference value android
boolean committed = PreferenceManager.getDefaultSharedPreferences(yourContext).edit().putBoolean(key, mValue).commit();