安卓preferences - 的区别是什么?区别、preferences

由网友(朝如青丝暮成雪)分享简介:的区别是什么,当我得到preferences为:preferenceManager.getDefaultShared preferences(getBaseContext());和获取preferences(Context.MODE_PRIVATE);解决方案 preferenceManager.getDefaul...

的区别是什么,当我得到preferences为:

  preferenceManager.getDefaultShared preferences(getBaseContext());
 

 获取preferences(Context.MODE_PRIVATE);
 

解决方案

  preferenceManager.getDefaultShared preferences(getBaseContext());
 
苹果实况文本 一加Breeno识屏对比 iOS到底有没有逐渐安卓化

将提供一个获得了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).

阅读全文

相关推荐

最新文章