Is there a method to set default values in shared preferences?
Here is my load preferences code
public void LoadPreferences() {
SharedPreferences sharedPreferences = getSharedPreferences(values, MODE_PRIVATE);
String strSavedMem1 = sharedPreferences.getString("MEM1", "");
String strSavedMem3 = sharedPreferences.getString("MEM3", "");
and here is my save preferences code
public void SavePreferences(String key, String value) {
SharedPreferences sharedPreferences = getSharedPreferences(values, MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(key, value);
editor.commit();
}
When you are setting preference with key and value,you are actually giving the value.So this time no question of using the default value.See, when you are retrieving the value you can define a default value if the value is not set previously.
if you get strSavedMem1=”default” then surely it is by default as you didn’t set any other value to MEM1 in the preference