android default values for shared preferences

前端 未结 3 1228
走了就别回头了
走了就别回头了 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:45

    Could you use the default value parameter of the getX() method?

    For example, to get a String called 'username', you could use this:

    String username = prefs.getString("username_key", "DefaultUsername");
    

    You can simply define your default values in your Preferences class.

提交回复
热议问题