Setting A Default Value In Sharedpreferences
Is there a method to set default values in shared preferences? Here is my load preferences code public void LoadPreferences() { SharedPreferences sharedPreferences
Solution 1:
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.
StringstrSavedMem1= sharedPreferences.getString("MEM1", "default");
if you get strSavedMem1="default" then surely it is by default as you didn't set any other value to MEM1 in the preference
Post a Comment for "Setting A Default Value In Sharedpreferences"