开发者

Android Shared Preferences Initialization

开发者 https://www.devze.com 2023-02-09 04:24 出处:网络
It is often nice t开发者_StackOverflowo have some default values in Shared Preferences to begin with.Is therea good way to initialize them from an xml file or property file? Looking for the best way t

It is often nice t开发者_StackOverflowo have some default values in Shared Preferences to begin with. Is there a good way to initialize them from an xml file or property file? Looking for the best way to do this. Thanks.


Read the answer in this question:

Android Preferences: How to load the default values when the user hasn't used the preferences-screen?


 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Make sure default values are applied.  In a real app, you would
        // want this in a shared function that is used to retrieve the
        // SharedPreferences wherever they are needed.
        PreferenceManager.setDefaultValues(getActivity(),
                R.xml.advanced_preferences, false);

}
0

精彩评论

暂无评论...
验证码 换一张
取 消