I have registered registerOnSharedPreferenceChangeListener
with my SharedPreferences
in my Activity. When I change the data saved with SharedPreferences
inside service running in different process, onSharedPreferenceChanged
is not called!
What should I do to make android call onSharedPreferenceChanged
?
Most likely, it is being garbage collected by gc. I have faced this problem before. Make a global variable which keeps a hard reference to the listener.
OnSharedPreferenceChangeListener listener = new SharedPreferences.OnSharedPreferenceChangeListener() {
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
// Implementation
}
};
The answer at SharedPreferences.onSharedPreferenceChangeListener not being called consistently explains it best
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