Android 偏好设置 xml 文件不支持/未与应用程序一起安装
我有一个应用程序,它使用两个共享首选项(即两个 xml 文件)来操作。它们被添加到我的 eclipse 项目中,我可以在 /res/xml 下看到这两个文件:preferences.xml 和 service_data.xml。
当我编译并运行我的程序时,它编译正常,没有问题或警告,但执行时就像不加载preferences.xml。我打开 DDMS 视图,使用文件资源管理器可以在 /data/data/com...myapp/shared_prefs 下看到仅安装和复制了 service_data.xml。没有preferences.xml。
在我的应用程序中,我使用以下命令打开两者(按此顺序):
SharedPreferences preferences = this.getSharedPreferences("preferences",0);
SharedPreferences service_data = this.getSharedPreferences("service_data",0);
Xml 文件看起来正确,事实上在添加 service_data.xml 之前,preferences.xml 运行正常
有人知道为什么preferences.xml 未安装且未打开吗?有什么可能的原因吗?
谢谢
I have an application which uses two sharedpreferences (so two xml files) to operate. They are added in my eclipse project, I can see both under /res/xml as two files: preferences.xml and service_data.xml.
When I compile and run my program, it compile OK without problems or warnings, but when executed is like preferences.xml does not load. I open DDMS view, and with file explorer I can see under /data/data/com...myapp/shared_prefs that only service_data.xml has been installed and copied. There is no preferences.xml.
In my app, I open both with (in this order):
SharedPreferences preferences = this.getSharedPreferences("preferences",0);
SharedPreferences service_data = this.getSharedPreferences("service_data",0);
Xml files looks correct, and in fact preferences.xml were running ok before I added service_data.xml
Has someone an idea why preferences.xml is not installed and not opened? any tip of the possible cause?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了。
最初,Android 不会为首选项创建 xml。仅当要创建非默认值的新首选项时,才会添加 xml 文件。因此,所有对preferences.getString 的引用都必须具有正确的默认值。
Solved.
Initially, Android does not create an xml for preferences. Only when a new preference is going to be created that is not the default value is the xml file added. So it is necessary that all references to preferences.getString has the proper default value.