Note that there are some explanatory texts on larger screens.

plurals
  1. PORingtonePreference not saving in PreferenceActivity
    primarykey
    data
    text
    <p>I am using <code>PreferenceScreen</code> to set some user preferences in my Android app. It works perfectly for several <code>ListPreference</code> and <code>CheckboxPreference</code> items, however I cannot get <code>RingtonePreference</code> to work properly. The appropriate ringtone dialog displays, and can be selected, but the selection is never saved.</p> <p>My app only plays the default sound no matter what I select. Whenever I re-open the ringtone dialog (either immediately after making a selection, or after exiting the app and coming back in) it always just has the default item selected. I have a field to display the preference value, and it always shows the default sound is selected, even after changing it on the preferences screen. I also confirmed that the appropriate xml file on my device (in /data/data/myapp/shared_prefs) is not changing when I monitor it with DDMS. If I change other items (such as a <code>CheckboxPreference</code>), I see the shared_prefs file change realtime. I have stripped my <code>PreferenceScreen</code> to the bare minimum and it still behaves the same. I tried changing key names, defaults, and clearing app data on my phone.. nothing seems to work.</p> <p>I did find 2 similar questions already posted on SO (<a href="https://stackoverflow.com/questions/7587668/ringtone-preference-not-saving-choice">here</a> and <a href="https://stackoverflow.com/questions/12052096/ringtonepreference-doesnt-save-its-value">here</a>), but they are several months old, with no answers and/or the person asking the question gave up and tried another method. I'd like to figure out why it does not appear to work as designed.. or at least, find a suitable method to get the same thing done.</p> <p>The relevant portions of my code are below.. thanks in advance!</p> <p><strong>/res/xml/preferences.xml:</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" &gt; &lt;RingtonePreference android:key="alertSound" android:ringtoneType="notification" android:summary="Select audio notification sound" android:title="Alert Sound" &gt; &lt;/RingtonePreference&gt; &lt;/PreferenceScreen&gt; </code></pre> <p><strong>/src/myapp/EditPrefsActivity.java:</strong></p> <pre><code>public class EditPrefsActivity extends PreferenceActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); settings = PreferenceManager.getDefaultSharedPreferences(this); addPreferencesFromResource(R.xml.preferences); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload