listener sharedpreferences
<p>I've a problem with this code. I want keep preferences values in my app but I've problem with the listener. Does not work, its does not save new values. Any idea about error(s)?</p>

<p>EDIT: onResume() works because when I open an activity on my app and close it, the value of sharepreferences is correct. Dialogs and activities does not keep values.</p>

<pre><code>public void onCreate(){
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
          listener = new SharedPreferences.OnSharedPreferenceChangeListener() {
              public void onSharedPreferenceChanged(SharedPreferences prefs, String listpref) {
                    if(!preferencesChanged)preferenze();

            }
              };
      sp.registerOnSharedPreferenceChangeListener(listener);
</code></pre>

<p>// there are some buttons and other info activities called by intents.
// a textview that show a value from array and nothing</p>

<pre><code>    public void onPause() {
        super.onPause();
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
        sp.unregisterOnSharedPreferenceChangeListener(listener);

protected void onResume() {
        super.onResume();
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
        listener = new SharedPreferences.OnSharedPreferenceChangeListener() {
        public void onSharedPreferenceChanged(SharedPreferences prefs, String listpref) {
        preferencesChanged = true;
                }
        };
        sp.registerOnSharedPreferenceChangeListener(listener);

protected void onStop(){
        super.onStop();
        if(preferencesChanged){
            //Update the app
            preferenze();
        }


public void preferenze()
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

        CheckboxPreference = prefs.getBoolean("checkboxPref", true);
        ListPreference = prefs.getString("listpref", "");
</code></pre>

<p>// others variables and most if/else</p>

<p>Preferences.xml</p>

<pre><code>public class Preferences extends PreferenceActivity implements OnSharedPreferenceChangeListener{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            addPreferencesFromResource(R.layout.preferences);

    }

    @Override
    public void onSharedPreferenceChanged(SharedPreferences prefs, String listpref) {
</code></pre>
