In my activity, on user’s request for preferences screen, I call:
startActivity(new Intent(this, Preferences.class));
Preferences class is defined like this:
public class Preferences extends PreferenceActivity implements OnSharedPreferenceChangeListener {
...
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
...
}
}
I need to implement OnSharedPreferenceChangeListener in my Preferences class becase I want to be able to – for example – disable a preferences item based on a specific selection.
But I would need to implement it in my main Activity, to react to the preference changes.
Unfortunately onSharedPreferenceChanged() fires only in my Preferences class, and not in my main activity: how can I force it to be fired in bot activities?
Or – how can I manually call onSharedPreferenceChanged() in my main activity from onSharedPreferenceChanged() in Preferences activity?
in your main activity, you can register a listener for prefs changes:
and then you would implement
SharedPreferences.OnSharedPreferenceChangeListenerin your activity, with your ownonSharedPreferenceChangedmethod.