SharedPreferences.onSharedPreferenceChangeListener not being called consistently

Posted by synic on Stack Overflow See other posts from Stack Overflow or by synic
Published on 2010-03-30T04:55:36Z Indexed on 2010/03/30 5:03 UTC
Read the original article Hit count: 513

Filed under:

I'm registering a preference change listener like this (in the onCreate() of my main activity):

SharedPreferences prefs = 
    PreferenceManager.getDefaultSharedPreferences(this);

prefs.registerOnSharedPreferenceChangeListener(
    new SharedPreferences.OnSharedPreferenceChangeListener() {
        public void onSharedPreferenceChanged(
            SharedPreferences prefs, String key) {

            System.out.println(key);
        }
    });

The trouble is, the listener is not always called. It works for the first few times a preference is changed, and then it is no longer called until I uninstall and reinstall the app. No amount of restarting the application seems to fix it.

I found a mailing list thread reporting the same problem, but no one really answered him. What am I doing wrong?

© Stack Overflow or respective owner

Related posts about android