开发者

Android preferences - what is the difference?

开发者 https://www.devze.com 2023-02-24 04:36 出处:网络
What is the difference, when I get preferences as: PreferenceManager.getDefaultSharedPreferences(getBaseContext());

What is the difference, when I get preferences as:

PreferenceManager.getDefaultSharedPreferences(getBaseContext());

and

g开发者_如何学JAVAetPreferences(Context.MODE_PRIVATE);


PreferenceManager.getDefaultSharedPreferences(getBaseContext());

Will provide an access to a preferences file that is global for the whole application package ; any activity can access the preferences (internaly, the xml file holding the preferences will be named your.application.package_preferences.xml).

contextInstance.getPreferences(Context.MODE_PRIVATE);

Will provide preferences only for the contextInstance class: only instances of the context's class can access these preferences (said your package is still your.application.package and you're in your.application.package.foo.MyActivity, internaly the preferences file is foo.MyActivity.xml).

0

精彩评论

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