How to listen for preference changes within a PreferenceFragment?

I believe you just need to register/unregister the Listener in your PreferenceFragment and it will work.

@Override
public void onResume() {
    super.onResume();
    getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);

}

@Override
public void onPause() {
    getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
    super.onPause();
}

Depending on what you want to do you may not need to use a listener. Changes to the preferences are committed to SharedPreferences automatically.

Leave a Comment

tech