Question: I have

```
SharedPreferences myPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

```

and 

```
myPreferences.getBoolean("checkbox", true)

```

So, how can my main activity know when user change preferences state?
For example if user don't wont to get notifications any more.
Thanks.

Answer: 
You need to implement the onSharedPreferenceChangeListener interface. Then register to receive change updates in your onCreate/onStart:

```
myPreferences.registerOnSharedPreferenceChangeListener();

```

In your listener you do something like this:

```
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if (key.equals("MyKey")) {
    // Do something.
} else if (key.equals("MyOtherKey")) {
    // Do something else.
      }
}

```

Remember to remove the listener in onStop/onDestroy.
You can create a static boolean that is changed whenever a preference is changed, or when your preference activity is started. The purpose of this boolean is to let your main activity know the preferences are dirty and need to be reloaded. They should be reloaded `onResume` if the `mDirty` flag is true.

Another option is to just reload all the preferences `onResume`, regardless. This may not be as efficient, but if you don't have loads of preferences, it's fine.

The most efficient way would be to set onPreferenceChanged listeners for all your prefs in your prefs activity, the prefs then notify the activity only when they actually change. This solves the case when your user enters your prefs activity, but doesn't actually change anything.