-1

We investigated the strange behavior.

we have OnSharedPreferenceChangeListener created in main activity and stored on static field:

public static SharedPreferences.OnSharedPreferenceChangeListener listener = null;

Also we created and registered it in onCreate method.

We have three buttons which change the setting and call commit in such way:

                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
                SharedPreferences.Editor editor = prefs.edit();
                editor.putString("setting1", "value");
                editor.commit();

The problem is in following:

The onSharedPreferenceChanged didn't raised for the first time when we clicked the button! When we clicked for the second time all is OK. Why the event didn't raised for the first time?

Sasha
  • 1,958
  • 1
  • 19
  • 33
  • If you do not understand the question, please, look this one http://stackoverflow.com/questions/2542938/sharedpreferences-onsharedpreferencechangelistener-not-being-called-consistently – Sasha Oct 16 '15 at 15:24

1 Answers1

0

I hope it will help someone:

The problem was that we registered it in onCreate method. It is working if you will create it in onResume method.

Also, please, look on this answer for common problem with SharedPreference: SharedPreferences.onSharedPreferenceChangeListener not being called consistently

Community
  • 1
  • 1
Sasha
  • 1,958
  • 1
  • 19
  • 33