安卓preferences - 的区别是什么? [英] Android preferences - what is the difference?
问题描述
的区别是什么,当我得到preferences为:
preferenceManager.getDefaultShared preferences(getBaseContext());
和
获取preferences(Context.MODE_PRIVATE);
preferenceManager.getDefaultShared preferences(getBaseContext());
将提供一个获得了preferences文件,它是全球整个应用程序包;任何活动都可以访问preferences(internaly,xml文件抱着preferences将被命名为 your.application.package_ preferences.xml
)。
contextInstance.get preferences(Context.MODE_PRIVATE);
将只提供了contextInstance类preferences:上下文的类可以访问这些preferences(说你的包仍然是唯一的实例 your.application.package
和你在 your.application.package.foo.MyActivity
,internaly的preferences文件是 foo.MyActivity.xml
)。
What is the difference, when I get preferences as:
PreferenceManager.getDefaultSharedPreferences(getBaseContext());
and
getPreferences(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
).
这篇关于安卓preferences - 的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!