Don't call edit() multiple times.

Every call to edit() creates a new "change session", so you're changing the
value but not committing the change, and then starting a new changeset and
committing it with no new values.

--
Kostya Vasilyev -- http://kmansoft.wordpress.com

09.10.2010 2:36 пользователь "JoelDuggan" <[email protected]> написал:

Hey there all,

I'm having a problem that i don't know how to resolve.

I have a broadcast receiver catching a call from the system.  I need
this receiver to set a flag so that the next time my app runs it can
do something different.

I am trying to do this with a shared pref but it is not working.

In the receiver I do:

     SharedPreferences sharedPreferences =
context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
     sharedPreferences.edit().putBoolean("changed", true);
     sharedPreferences.edit().commit();

Then when i start my app I check like so:

        sharedPreferences = getSharedPreferences(PREFS_NAME,
MODE_PRIVATE);
        if (sharedPreferences.getBoolean("changed", false)){
           hasChanged = true;
           sharedPreferences.edit().putBoolean("changed", false);
           sharedPreferences.edit().commit();
        }


This does not work.  If I download the file from the emulator after
the receiver has triggered it is empty.  It exists but there is no key
value pair.

What am I doing wrong?  Is there a better way to flag my app to run
differently on next startup?

Any help???

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]<android-developers%[email protected]>
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to