title: Android : Where should a OnSharedPreferenceChangeListener be defined/registered
body: <p>Design question basically - having a <code>PreferenceActivity</code> should one make it implement <code>OnSharedPreferenceChangeListener</code> or should one define this functionality in another class - say in an inner class ? Is there some reason one would prefer the one over the other approach ?  </p>
  
  <p>Also where should one register the listener ? I mean <a href="http://developer.android.com/guide/topics/ui/settings.html#ReadingPrefs" rel="nofollow noreferrer">the docs</a> and common sense dictate to register/unregister in <code>onResume/onPause</code> respectively but having seen <a href="https://stackoverflow.com/q/2542938/281545">a</a> <a href="https://stackoverflow.com/a/13669689/281545">zillion</a> <a href="https://stackoverflow.com/a/10808682/281545">registrations</a> in <code>onCreate</code> I just wonder if I am missing something.</p>
  
  <p>Also I am not quite certain if a failure to unregister (so <a href="https://stackoverflow.com/a/6105761/281545">here</a> for instance unregistering may not be called as <code>onStop</code> is not guaranteed to be called) would necessarily lead to a leak. So if I have for instance </p>
  
  <pre><code>class MyPref extends PreferenceActivity implements
              OnSharedPreferenceChangeListener {
      SharedPreferences sharedPreferences;
      // init sharedPreferences
      onStart(){
          sharedPreferences.registerOnSharedPreferenceChangeListener(this);
      }
      // no unregistration
  }
  </code></pre>
  
  <p>Would this leak the <code>MyPref</code> instance once I go back to one of my other activities ?</p>
  
  <p>Lastly - would the same considerations apply to <code>OnPreferenceChangeListener</code> ?</p>
  
  <p>Edit : coming back to that I see no way to actually unregister the <code>OnPreferenceChangeListener</code> - am I blind ??</p>