Android 偏好 - 有什么区别? [英] Android preferences - what is the difference?

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

问题描述

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

What is the difference, when I get preferences as:

PreferenceManager.getDefaultSharedPreferences(getBaseContext());

getPreferences(Context.MODE_PRIVATE);

推荐答案

PreferenceManager.getDefaultSharedPreferences(getBaseContext());

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

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);

将只为 contextInstance 类提供首选项:只有上下文类的实例可以访问这些首选项(说你的包仍然是 your.application.package 而你在 your.application.package.foo.MyActivity,内部的首选项文件是 foo.MyActivity.xml).

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).

这篇关于Android 偏好 - 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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