0

I have a Preference activity which uses a List Preferences as defined by my XML file:

<?xml version="1.0" encoding="utf-8"?>
    <PreferenceScreen
            xmlns:android="http://schemas.android.com/apk/res/android">
        <PreferenceCategory
                android:title="sync">
            <ListPreference
                    android:key="key_sync_period"
                    android:title="Sync"
                    android:summary="%s"
                    android:dialogTitle="Sync frequency"
                    android:entries="@array/sync_period_entries"
                    android:entryValues="@array/sync_period_values"
                    android:defaultValue="1800" />
        </PreferenceCategory>
    </PreferenceScreen>

arrays.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="sync_period_entries">
        <item>15 min</item>
        <item>30 min</item>
        <item>45 min</item>
        <item>1 hour</item>
    </string-array>

    <string-array name="sync_period_values">
        <item>900</item>
        <item>1800</item>
        <item>2700</item>
        <item>3600</item>
    </string-array>
</resources>

When I start my app, change this setting, I see the following:

  • the app writes to a defaultSharedPreference file value = 1800
  • I change it to "15 min" and see value = 900 - ok, all right
  • I change it to "45 min" and see value = 60 - ???
  • I change it to "1 hour" and see value = 180 - ???????
  • I change again it to "30 min" and see value = 1800
  • I change it to "1 hour" and see value = 180 - why?

Why do I see these values (60, 180)? Where did they come from?

Update 1:

if (key.equals("key_sync_period"))
{
    ListPreference syncPref = (ListPreference) findPreference(key);
    syncPref.setSummary(syncPref.getEntry());
    long seconds = Long.valueOf(sharedPreferences.getString(key, "1800"));
}

The system writes defaultSharedPreferences. I see preference file from ddms and see that the system written wrong value.

ilyamuromets
  • 403
  • 1
  • 7
  • 18
  • just try something....clear the application data. I have faced similar problems in the past and this just came from values that were stored in previous made tests.. – Opiatefuchs Oct 29 '14 at 13:00
  • @Opiatefuchs I cleaned the cache, I reinstall the app, I've rebooted "idea", I've rebooted a phone, but nothing helps.. – ilyamuromets Oct 29 '14 at 13:15
  • ok, can You post the code where You get the values? – Opiatefuchs Oct 29 '14 at 13:22
  • @Opiatefuchs I update my post (Update 1) – ilyamuromets Oct 29 '14 at 13:30
  • are there any equal keys in Your project? It is possible that You have just not seen this and You are using the keys on other parts....? Or different arrays with the same name? – Opiatefuchs Oct 29 '14 at 13:49
  • @Opiatefuchs I found problem. I deleted the project and imported it again in idea.... and problem was solved. Thanks, your first answer was in the right direction. – ilyamuromets Oct 29 '14 at 15:05

1 Answers1

0

The problem was in the Idea 12CE, I deleted the project and imported it again... and problem was solved.

ilyamuromets
  • 403
  • 1
  • 7
  • 18