Setting a default value in sharedpreferences

前端 未结 1 450
无人共我
无人共我 2021-01-22 11:01

Is there a method to set default values in shared preferences?

Here is my load preferences code

        public void LoadPreferences() {
        SharedPre         


        
相关标签:
1条回答
  • 2021-01-22 11:15

    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.

    String strSavedMem1 = 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

    0 讨论(0)
提交回复
热议问题