4

I have a ringtone preference in my app but when I select the tone I want, it does not get stored in the preference value. I can click the preference again and it will not show what I just selected.

here is the XML

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="Audio Settings">
        <CheckBoxPreference 
            android:key="SMS_PREF_TTS"
            android:title="Say name of sender"
            android:summary="When a person in your contact list sends you a sms/mms message its says their name"
            android:defaultValue="false">
        </CheckBoxPreference>
        <CheckBoxPreference 
            android:key="SMS_PREF_TTS_MSG"
            android:title="Say Message"
            android:summary="Will say the message of sender from contact list"
            android:dependency="SMS_PREF_TTS"
            android:defaultValue="false">
        </CheckBoxPreference>
        <RingtonePreference 
            android:key="SMS_PREF_SOUND"
            android:title="Change Sound"
            android:ringtoneType="notification"
            android:summary="Select the notification Sound"
            android:dialogTitle="Change Sound"
            android:defaultValue="Silent">
        </RingtonePreference>
</PreferenceCategory>
</PreferenceScreen>

and the weird thing is I just wrote another xml for another part of my app with a ringtone preference looking the same way and that one works so I dont understand.

here is the working one

<RingtonePreference
        android:key="CAL_PREF_TONE"
        android:title="Default ringtone"
        android:summary="Select default notification ringtone"
        android:ringtoneType="notification"
        android:defaultValue="Silent"
        android:dependency="CAL_PREF_ON">
    </RingtonePreference>
tyczj
  • 71,600
  • 54
  • 194
  • 296
  • The only thing I could think of is that you're using SMS_PREF_SOUND in some other pref and this overwrites your choice. Other than that (unless you're doing something in your PreferenceActivity) there's absolutely no reason it won't be stored. – IncrediApp Sep 28 '11 at 18:31
  • I have tried changing the `key` too and it still does not save it – tyczj Sep 28 '11 at 18:39

6 Answers6

4

If you have overriden onActivityResult() and forgotten to call super.onActivityResult() you can see this problem as well.

See RingtonePreference not firing OnPreferenceChangeListener

Community
  • 1
  • 1
Scott W
  • 9,742
  • 2
  • 38
  • 53
3

I had the same problem. In the AndroidManifest.xml file I had my preference activity set with noHistory="true". Once I removed it everything worked correctly.

Udo Held
  • 12,314
  • 11
  • 67
  • 93
Mike
  • 31
  • 2
2

I ended up saving it manually by registering a onPreferenceClickListener and getting the result

tyczj
  • 71,600
  • 54
  • 194
  • 296
2

I managed to resolve this by removing android:launchMode="singleInstance" and android:excludeFromRecents="true" from the settings activity entry on AndroidManifest.xml (setting either or both of these options will cause the same issue). It seems to be a bug on Android.

Majed
  • 56
  • 2
  • 6
1

the solution I used was provided by Udo Held, I just wanted to add one thing, I had to remove the launchMode="singleInstance" and I am now using android:launchMode="singleTask" and everything works fine. Just in case someone else needs a launchMode, this one worked for me.

JenniferG
  • 602
  • 1
  • 5
  • 13
0

I just had the same problem, but then I reviewed my codes, when I read the preference:

SharedPreferences settings = 
context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);

Which is wrong, the correct solution is:

SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);

Hope it helps

hungson175
  • 4,373
  • 6
  • 22
  • 21