Android偏好 - 有什么区别?

LA_*_*LA_ 12 android android-preferences android-sharedpreferences

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

PreferenceManager.getDefaultSharedPreferences(getBaseContext());
Run Code Online (Sandbox Code Playgroud)

getPreferences(Context.MODE_PRIVATE);
Run Code Online (Sandbox Code Playgroud)

Ocu*_*cuS 24

PreferenceManager.getDefaultSharedPreferences(getBaseContext());
Run Code Online (Sandbox Code Playgroud)

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

contextInstance.getPreferences(Context.MODE_PRIVATE);
Run Code Online (Sandbox Code Playgroud)

将仅为contextInstance类提供首选项:只有上下文类的实例才能访问这些首选项(表示您的程序包仍然存在,your.application.package而您正在your.application.package.foo.MyActivity使用首选项文件foo.MyActivity.xml).