安卓preferences - 的区别是什么? [英] Android preferences - what is the difference?

查看:139
本文介绍了安卓preferences - 的区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的区别是什么,当我得到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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆