2011-09-28 98 views
4

我在我的应用程序中有一个铃声首选项,但是当我选择我想要的铃声时,它不会存储在首选项值中。我可以再次点击该偏好设置,它不会显示我刚刚选择的内容。铃声首选项不保存选择

这里是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> 
+0

我能想到的唯一的事情就是你在其他一些pref中使用了SMS_PREF_SOUND,并且这会覆盖你的选择。除此之外(除非你在PreferenceActivity中做某件事),绝对没有理由不存储它。 – IncrediApp

+0

我也尝试过改变'钥匙',它仍然不能保存它 – tyczj

回答

2

我最终通过注册onPreferenceClickListener并得到结果手动保存它

0

我有同样的问题,但后来我检讨我的代码,当我读到的偏好:

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

哪项是错误的,正确的解决方案是:

SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); 

希望它有助于

3

我有同样的问题。在AndroidManifest.xml文件中,我的偏好设置为noHistory="true"。一旦我删除它,一切工作正常。

2

我设法解决此除去从AndroidManifest.xml中设置活动入口android:launchMode="singleInstance"android:excludeFromRecents="true"(设置一个或两个的这些选项将导致相同的问题)。这似乎是Android上的一个错误。

1

我使用的是由乌提供的解决方案举行,我只是想补充一点,我不得不删除launchMode="singleInstance",现在我使用android:launchMode="singleTask",一切工作正常。以防万一别人需要launchMode,这个为我工作。