阅读共享preferences当你没有设置文件名 [英] Read SharedPreferences when you haven't set the name of the file

查看:111
本文介绍了阅读共享preferences当你没有设置文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在createa Android上preferenceScreen,您的应用程序创建的设置的默认共享preferences文件。
我想读这个名字,或者没有specifing的名字来取得的参考。

When you createa a PreferenceScreen on Android, your application creates a default SharedPreferences file for the settings. I want to read this name, or get a reference without specifing the name.

目前我使用的:

SharedPreferences prefs = ctx.getSharedPreferences("prefs", 0);
SharedPreferences.Editor ed=prefs.edit();

但是,这将返回preference的另一个副本。当我检查了文件夹/数据/数据​​/ myapk / shared_ preFS

But this returns another copy of the preference. When I checked the folder in /data/data/myapk/shared_prefs

我看到两个文件,​​一个名为prefs.xml另一个是_ preferences.xml(这是由preferenceActivity创建)我的[包名];

I see two files, one named prefs.xml and the other is my [package name]_preferences.xml (this was created by the PreferenceActivity);

我如何使用默认的文件名使用的共享preference的一个实例,所以我不应该为它提到一个名字吗?

How do I get an instance of the shared preference with the usage of the default file name, so I should not mention a name for it?

推荐答案

我相当肯定你想要的<$c$c>$p$pferenceManager.getDefaultShared$p$pferences(Context上下文)

I'm fairly sure you want PreferenceManager.getDefaultSharedPreferences(Context context).

这篇关于阅读共享preferences当你没有设置文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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