铃声首选项不保存选择

时间:2011-09-28 18:19:50

标签: android preferences ringtone

我的应用程序中有铃声首选项但是当我选择我想要的铃声时,它不会存储在首选项值中。我可以再次单击首选项,它不会显示我刚刚选择的内容。

这是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>

而奇怪的是我刚为我的应用程序的另一部分写了另一个xml,其中一个铃声偏好看起来一样,而且一个有效,所以我不明白。

这是工作的

<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>

6 个答案:

答案 0 :(得分:4)

如果您覆盖onActivityResult()并忘记致电super.onActivityResult(),您也可以看到此问题。

请参阅RingtonePreference not firing OnPreferenceChangeListener

答案 1 :(得分:3)

我遇到了同样的问题。在AndroidManifest.xml文件中,我的首选项活动设置为noHistory="true"。一旦我删除它一切正常。

答案 2 :(得分:2)

我最终通过注册onPreferenceClickListener并获得结果

手动保存

答案 3 :(得分:2)

我设法通过从AndroidManifest.xml上的设置活动条目中删除android:launchMode="singleInstance"android:excludeFromRecents="true"来解决此问题(设置其中一个或两个选项都会导致同样的问题)。这似乎是Android上的一个错误。

答案 4 :(得分:1)

我使用的解决方案是由Udo Held提供的,我只是想添加一件事,我必须删除launchMode="singleInstance",我现在正在使用android:launchMode="singleTask",一切正常。万一其他人需要一个launchMode,这个对我有用。

答案 5 :(得分:0)

我遇到了同样的问题,但是当我阅读偏好时,我查看了我的代码:

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

哪个错了,正确的解决方案是:

SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);

希望有所帮助

相关问题