【发布时间】:2011-02-09 05:53:49
【问题描述】:
在 Shared Preferences 中设置一些默认值通常会很好。有没有从 xml 文件或属性文件初始化它们的好方法?寻找最好的方法来做到这一点。谢谢。
【问题讨论】:
标签: android initialization sharedpreferences
在 Shared Preferences 中设置一些默认值通常会很好。有没有从 xml 文件或属性文件初始化它们的好方法?寻找最好的方法来做到这一点。谢谢。
【问题讨论】:
标签: android initialization sharedpreferences
@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);
}
【讨论】: