I’ve got an “activity a” which reads some values from SharedPreferences and display them in a TextView, then I call “activity b” where the values from SharedPreferences get updated and written back to SharedPreferences. Finally I go back to “activity a” by pressing the back-button, now the new (updated) values should be read from SharedPreferences and shown in the TextView. But here comes the problem, the values just read from SharedPreferences are still not updated (are not the new ones set by activity b) (got it from logcat output), how comes that? Does SharedPrefs need some kind of manual refresh?
If I restart “activity a” everything works just fine and the new values are shown properly. What’s the matter?
I call the method to read and show the values from onResume() in “activity a”.
I also tried to re-instantiate the SharedPrefs-Object (with getSharedPreferences()) but it doesn’t help either.
Thanks in advance!
Are you calling the commit() method in activity b to save the new values.
Eg something like:
And secondly you can finish() the activity a before being sent to activity b, then from activity b a new instance of activity a will be created and onCreate() will be called.
Alternatively you can refresh the preferences in the onStart() because your activity is probably “no longer visible” when sent to activity b.
See http://developer.android.com/guide/topics/fundamentals/activities.html to see the activity lifecycle.