title: How to detect if changes were made in the preferences?
body: <p>I have a class that extends PreferenceActivity and shows the preference screen of my app. Is it possible to check if any changes were made to the preferences?</p>
  
  <p>This helps...</p>
  
  <p><a href="http://developer.android.com/reference/android/content/SharedPreferences.OnSharedPreferenceChangeListener.html" rel="noreferrer">http://developer.android.com/reference/android/content/SharedPreferences.OnSharedPreferenceChangeListener.html</a></p>
  
  <p>Other related post:
  <a href="https://stackoverflow.com/questions/2542938/sharedpreferences-onsharedpreferencechangelistener-not-being-called-consistently">SharedPreferences.onSharedPreferenceChangeListener not being called consistently</a></p>
  
  <hr>
  
  <pre><code>public class PreferenceClass extends PreferenceActivity {
  
      OnSharedPreferenceChangeListener listener;
  
      public void onCreate(Bundle savedInstanceState) {
          SharedPreferences prefs = this.getSharedPreferences("settings", 0);
          listener = new SharedPreferences.OnSharedPreferenceChangeListener() {
  
              public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
                  int flag = 1;
              }
          };
          prefs.registerOnSharedPreferenceChangeListener(listener);
          super.onCreate(null);
          addPreferencesFromResource(R.xml.settings);
      }
  }
  </code></pre>