Every other preference I have fires its OnPreferenceChangeListener. However, my RingtonePreference it doesn't:
p = getPreferenceScreen().findPreference("pref_tone");
String rname = preferences.getString("pref_tone",Settings.System.DEFAULT_RINGTONE_URI.toString());
String name = ringtoneToName(rname);
p.setSummary(name);
p.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
// Never hits here!
String v = (String) newValue;
preference.setSummary(ringtoneToName(v));
return true;
}
});
Note that a RingtonePreference uses an Activity for the ringtone picker.
If you are using a RingtonePreference in a support PreferenceFragment (
android.support.v4.preference.PreferenceFragment
) then the RingtonePreference ends up erroneously using the parent Activity instead of the PreferenceFragment when callingstartActivityForResult
. This means that theonActivityResult
callback gets called on the parent Activity as well. The easiest workaround to fix this problem is to overrideonActivityResult
in the parent Activity and make sure it forwards the callback to the PreferenceFragment. For example like this:Those who are still facing problem, if you are using preference fragment then add the following code inside the preference fragment`
After this your onPreferenceChange method should get called
onActivityResult had to call super.onActivityResult is the fix