【问题标题】:Android preferences - what is the difference?Android 偏好设置 - 有什么区别?
【发布时间】:2011-08-04 21:24:46
【问题描述】:

当我得到偏好时有什么区别:

PreferenceManager.getDefaultSharedPreferences(getBaseContext());

getPreferences(Context.MODE_PRIVATE);

【问题讨论】:

    标签: android android-preferences android-sharedpreferences


    【解决方案1】:
    PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    

    将提供对整个应用程序包的全局首选项文件的访问;任何活动都可以访问首选项(在内部,保存首选项的 xml 文件将命名为your.application.package_preferences.xml)。

    contextInstance.getPreferences(Context.MODE_PRIVATE);
    

    将只为 contextInstance 类提供首选项:只有上下文类的实例可以访问这些首选项(假设您的包仍然是 your.application.package 而您在 your.application.package.foo.MyActivity 中,内部首选项文件是 foo.MyActivity.xml)。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-27
    • 1970-01-01
    • 2014-06-07
    • 1970-01-01
    • 2012-05-19
    • 1970-01-01
    • 2023-03-11
    相关资源
    最近更新 更多