preferences and listener
<p>This code runs and seems is ok. If I try on old device (2.x low ram) i.e. rotating emulator, after 5/6 rotate emulator crashes. Two days to study how resolve but I don't understand how... I commented unregister listener because if I decomment those lines preferences are not saved. Any help?</p>

<pre><code>    public void onCreate(Bundle savedInstanceState){ 
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);

    preferenze();

[...]
// buttons, array, dialogs
[...]


    protected void onResume() {
            super.onResume();
            this.doubleBackToExitPressedOnce = false;
            SharedPreferences prefs3 = PreferenceManager.getDefaultSharedPreferences(this);
            listener = new SharedPreferences.OnSharedPreferenceChangeListener() {
              public void onSharedPreferenceChanged(SharedPreferences prefs, String 

    listpref) {       
                      Log.i("MyActivity", "MyClass.getView() — onCreate, preferencesChanged = " +                   preferencesChanged);

                  preferencesChanged = true;
                  if(preferencesChanged)preferenze();
                  }   };
            prefs3.registerOnSharedPreferenceChangeListener(listener);


    protected void onStop(){
    super.onStop();
    Toast.makeText(this, "onStop", Toast.LENGTH_LONG).show();

    if(preferencesChanged){
        //Update the app
        preferenze();
    }




    public void onPause() {
    super.onPause();

//        If I decomment these 2 lines, listener does not update preferences.

//        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
//        sp.unregisterOnSharedPreferenceChangeListener(listener);



    private void preferenze() {

            SharedPreferences prefs = `PreferenceManager.getDefaultSharedPreferences(getBaseContext());`

            CheckboxPreference = prefs.getBoolean("checkboxPref", true);
            ListPreference = prefs.getString("listpref", "");
            numeronotifiche = prefs.getString("notify", "");
            Sound = prefs.getString("sound", "");
            barranotifiche = prefs.getBoolean("keep", false);

    natura = prefs.getBoolean("suoninaturasino", false);
    snatura = prefs.getString("suoninaturascelta", "");
    snaturaold = prefs.getString("snaturaoldvalue", "");

    if (natura){
        startService(new Intent(this, UnUsedService.class));
    }
    else {
        stopService(new Intent(this, UnUsedService.class));
    }

    if (barranotifiche){
        showNotification();
    }
        else {
            cancelNotification();
        }

    GestioneAllarme alarm = new GestioneAllarme();
    if (CheckboxPreference){
        if (numeronotifiche.equals("3")){
        alarm.CancelAlarm(this);
        alarm.SetAlarm3(this);
    }
        else if (numeronotifiche.equals("1")){
            alarm.CancelAlarm(this);
            alarm.SetAlarm1(this);
        }
        else if (numeronotifiche.equals("2")){
            alarm.CancelAlarm(this);
            alarm.SetAlarm2(this);
        }
        else {
        alarm.SetAlarm2(this);
        }
    }
    else {
        GestioneAllarme alarm2 = new GestioneAllarme();
        alarm2.CancelAlarm(this);
        }   

    if (Sound.equals("")){
        Sound = "2";
        Editor editor = prefs.edit();
        editor.putString("sound", "2");
        editor.commit();
    }


    if (ListPreference.equals("")){
        ListPreference = "1500";

      Editor editor = prefs.edit();
      editor.putString("listpref", "1500");
      editor.putInt("indexfade", 1500);
      editor.commit();

    }

    if (numeronotifiche.equals("")){
        numeronotifiche = "2";
        Editor editor = prefs.edit();
          editor.putString("numeronotifiche", "2");
          editor.commit();
    }


    fade = Integer.parseInt(ListPreference);
    notify = Integer.parseInt(numeronotifiche);



    if (fade == 500){
        animazione = R.style.MyCustomTheme1;
        fadein = R.anim.fadein500;
        fadeout = R.anim.fadeout500;
    }
    else if (fade == 1000){
        animazione = R.style.MyCustomTheme2;
        fadein = R.anim.fadein1000;
        fadeout = R.anim.fadeout1000;
    }
    else if (fade == 1500){
        animazione = R.style.MyCustomTheme3;
        fadein = R.anim.fadein1500;
        fadeout = R.anim.fadeout1500;
    }
    else if (fade == 2000){
        animazione = R.style.MyCustomTheme4;
        fadein = R.anim.fadein2000;
        fadeout = R.anim.fadeout2000;
    }   


    }
</code></pre>

<p>log:</p>

<pre><code>D/dalvikvm(  229): GREF has decreased to 299
D/dalvikvm(  229): GC freed 16209 objects / 2008384 bytes in 84ms
D/ACRA    (  229): Sending request to https://docs.google.com/spreadsheet/formResponse?formkey=dFNyNHJJQ1ZvdVhlblg3aVl1LVNOSGc6MQ&amp;ifq
D/dalvikvm(   52): GREF has decreased to 399
D/dalvikvm(   52): GC freed 2988 objects / 121640 bytes in 102ms
D/dalvikvm(  139): GC freed 9431 objects / 407400 bytes in 13 sec
D/dalvikvm(   95): GC freed 13906 objects / 548224 bytes in 640ms
D/ACRA    (  229): SocketTimeOut - increasing time out to 10000 millis and trying again
W/ResponseProcessCookies(  229): Invalid cookie header: "Set-Cookie: NID=67=s-a9ypSbJtM_ebXLGubURTG3pPyV3GfsxDK8nFeygh9XxbKlfboxkATQYORH8fK4pQctOipMeTAkSg_hX-kMEmEJD7vLxTtho-8vkrOr4IVVIXID9UAvkbbLAMITHfZg;Domain=.google.com;Path=/;Expires=Sun, 14-Jul-2013 21:36:52 GMT;HttpOnly". Unable to parse expires attribute: Sun
D/ACRA    (  229): #checkAndSendReports - finish
D/ACRA    (  229): Wait for Toast + worker ended. Kill Application ? true
E/AndroidRuntime(  229): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime(  229): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
E/AndroidRuntime(  229):    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
E/AndroidRuntime(  229):    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:447)
E/AndroidRuntime(  229):    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
E/AndroidRuntime(  229):    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
E/AndroidRuntime(  229):    at android.content.res.Resources.loadDrawable(Resources.java:1705)
E/AndroidRuntime(  229):    at android.content.res.Resources.getDrawable(Resources.java:580)
E/AndroidRuntime(  229):    at android.view.View.setBackgroundResource(View.java:7186)
E/AndroidRuntime(  229):    at com.example.app.MainActivity.onCreate(MainActivity.java:2562)
E/AndroidRuntime(  229):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime(  229):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
E/AndroidRuntime(  229):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
E/AndroidRuntime(  229):    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3625)
E/AndroidRuntime(  229):    at android.app.ActivityThread.access$2300(ActivityThread.java:119)
E/AndroidRuntime(  229):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1867)
E/AndroidRuntime(  229):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(  229):    at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  229):    at android.app.ActivityThread.main(ActivityThread.java:4363)
E/AndroidRuntime(  229):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  229):    at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(  229):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime(  229):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime(  229):    at dalvik.system.NativeStart.main(Native Method)
I/Process (   52): Sending signal. PID: 229 SIG: 3
I/dalvikvm(  229): threadid=7: reacting to signal 3
I/dalvikvm(  229): Wrote stack trace to '/data/anr/traces.txt'
I/ARMAssembler(   52): generated scanline__00000077:03515104_00000000_00000000 [ 33 ipp] (47 ins) at [0x59fe0:0x5a09c] in 547256 ns
</code></pre>
