Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SharedPreferences not persistent

I am using a SharedPreferences in Android.Everything works great in the same session.

However once I relaunch the application, all of the preferences that were set from the previous session are lost.

Is there anything I need to specify to tell the SharedPreferences to hang around from run to run?

I am creating the preferences by calling

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);

Then I set properties by e.g.

preferences.edit().putString(key, value);

and I get it by

preferences.getString(key, defaultValue);

Thanks, Victor

like image 715
Victor Grazi Avatar asked Feb 09 '12 04:02

Victor Grazi


1 Answers

SharedPreferences are persistent accross relaunch, restart, I think the problem is you are not commiting the preferences, use following to store values in preferences:

Preferences.Editor edit=preferences.edit();
edit.putString(key, value);
edit.commit();
like image 175
jeet Avatar answered Sep 25 '22 02:09

jeet