android default values for shared preferences

前端 未结 3 1222
走了就别回头了
走了就别回头了 2021-01-18 00:50

I am trying to understand the SharedPreferences of Android. I am a beginner and don\'t know a lot about it.

I have this class I implemented for my app Preferences

3条回答
  •  时光说笑
    2021-01-18 01:37

    You can store default values in string resource:

    default_value
    

    and then get it as it follows:

    int ResId = context.getResources().getIdentifier(key_name, "string", context.getPackageName()));
    prefs.getString(key_name,context.getResources().getString(ResId);
    

提交回复
热议问题