Where are shared preferences stored?

2019-01-01 08:39发布

Where in an Eclipse project might one encounter a shared preferences file?

6条回答
不再属于我。
2楼-- · 2019-01-01 08:59

SharedPreferences are stored in an xml file in the app data folder, i.e.

/data/data/YOUR_PACKAGE_NAME/shared_prefs/YOUR_PREFS_NAME.xml

or the default preferences at:

/data/data/YOUR_PACKAGE_NAME/shared_prefs/YOUR_PACKAGE_NAME_preferences.xml

SharedPreferences added during runtime are not stored in the Eclipse project.

Note: Accessing /data/data/<package_name> requires superuser privileges

查看更多
旧时光的记忆
3楼-- · 2019-01-01 09:01

The data is stored on the device, in your application's private data area. It is not in an Eclipse project.

查看更多
大哥的爱人
4楼-- · 2019-01-01 09:02

Use http://facebook.github.io/stetho/ library to access your app's local storage with chrome inspect tools. You can find sharedPreference file under Local storage -> < your app's package name >

enter image description here

查看更多
墨雨无痕
5楼-- · 2019-01-01 09:03

Just to save some of you time...

On my Galaxy S v.2.3.3 Shared Preferences are not stored in:/data/data/YOUR_PACKAGE_NAME/shared_prefs/YOUR_PREFS_NAME.xml

but are now located in: /dbdata/databases/YOUR_PACKAGE_NAME/shared_prefs/YOUR_PREFS_NAME.xml

I believe they changed this in 2.3

查看更多
查无此人
6楼-- · 2019-01-01 09:04

Preferences can either be set in code or can be found in res/xml/preferences.xml. You can read more about preferences on the Android SDK website.

查看更多
无色无味的生活
7楼-- · 2019-01-01 09:13

I just tried to get path of shared preferences below like this.This is work for me.

File f = getDatabasePath("MyPrefsFile.xml");

if (f != null)
    Log.i("TAG", f.getAbsolutePath());
查看更多
登录 后发表回答