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;
}
});
onActivityResult had to call super.onActivityResult is the fix
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 calling startActivityForResult
. This means that the onActivityResult
callback gets called on the parent Activity as well. The easiest workaround to fix this problem is to override onActivityResult
in the parent Activity and make sure it forwards the callback to the PreferenceFragment. For example like this:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Fragment f = getSupportFragmentManager().findFragmentByTag(PREFERENCE_FRAGMENT_TAG);
if (f != null) {
f.onActivityResult(requestCode, resultCode, data);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With