4

I know this question is a little stupid but I cannot find where the settings of my preferences screen are stored.

I am using shared preferences this file is located at /data/data/my.package.name/shared_prefs/common.xml. However when I change something the changes are stored. I even implemented custom controls which can store their information so far. But however I cannot figure out where the settings are stored. /data/data/my.package.name/ is only one xml file which does not contain any related information. I also checked the virtual directories for multi user devices with no luck.

Here is my xml:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res/my.package.name"
    android:persistent="true" >

    <PreferenceCategory android:title="@string/settings_basics_group" >
        <EditTextPreference
            android:key="nickname"
            android:persistent="true"
            android:positiveButtonText="@string/setting_change_name"
            android:title="@string/settings_username" />
        <my.package.name.controls.EmailPreference
            android:key="mail"
            android:title="@string/settings_email"
            custom:domains="@array/known_email_domains" />
        <Preference
            android:summary="Mars"
            android:title="@string/settings_current_location" />
        <my.package.name.controls.DatePreference
            android:key="birthday"
            android:title="@string/settings_birthday" />
    </PreferenceCategory>
</PreferenceScreen>

I would be really happy if somebody could explain me where these settings are stored.

Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361
rekire
  • 47,260
  • 30
  • 167
  • 264
  • Please explain what "However when I change something the changes are stored" - do you mean "However when I change something the changes are ___not___ stored ___there___" – Mr_and_Mrs_D Feb 12 '14 at 22:51

2 Answers2

3

For older Android versions including Jelly Bean (API 16) and older the answer of Dalmas is correct. So feel free to upvote that answer.

Beginning with Jelly Bean MR1 (API 17) there are new rules about path due the multiuser support:

I figured out that the settings file is located in /data/user/##/my.package.name/shared_prefs/my.package.name_preferences.xml where ## is my numeric user id.

For solving that path you need the ApplicationContext there you need to reflect mLoadedAPK and there mDataDir. For now I'm happy with that I could get the path from the debugger. Sorry to everyone who wants a ready to use code snippet, you have to do that yourself.

Community
  • 1
  • 1
rekire
  • 47,260
  • 30
  • 167
  • 264
2

The app preferences are stored in the default shared preferences that you can retrieve with PreferenceManager.getDefaultSharedPreferences().

The XML file itself is located at /data/data/YOUR_PACKAGE_NAME/shared_prefs/YOUR_PACKAGE_NAME_preferences.xml

Dalmas
  • 26,409
  • 9
  • 67
  • 80
  • That is really helpful to know that I can access the settings in this way, but there is no such file. That **is** my problem. I can also eliminate that this settings are only in the memory. Even if I crash or shutdown my app this settings are stored. – rekire Jun 25 '13 at 08:25
  • What is your android version? – Dalmas Jun 25 '13 at 08:35
  • I'm trying that on a 4.2.2 device (API 17). But on another API 10 device with (2.3.5) the file is there. Strange. – rekire Jun 25 '13 at 08:36
  • 2
    I figgered out that the file is located in `/data/user/##/my.package.name/shared_prefs/my.package.name_preferences.xml` where `##` is my numeric user id. I cannot read this file from console but this mistery is sloved for me. For sloving that path you need the `ApplicationContext` there you need to reflect `mLoadedAPK` and there `mDataDir`. – rekire Jun 25 '13 at 09:58