【问题标题】:Android Shared Preferences InitializationAndroid 共享首选项初始化
【发布时间】:2011-02-09 05:53:49
【问题描述】:

在 Shared Preferences 中设置一些默认值通常会很好。有没有从 xml 文件或属性文件初始化它们的好方法?寻找最好的方法来做到这一点。谢谢。

【问题讨论】:

标签: android initialization sharedpreferences


【解决方案1】:
【解决方案2】:
 @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);

}

【讨论】:

    猜你喜欢
    • 2021-12-31
    • 1970-01-01
    • 2021-02-16
    • 2023-02-13
    • 2020-09-15
    • 2022-01-23
    • 2022-11-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多