Alex Rivera | Logout

SharedPreferences not persistent

Asked 2012-02-09T04:49:17.120
11

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

Edit
Report

1 Answer

2

to get value in pref

SharedPreferences pref1 = getSharedPreferences(PREFS_NAME, 0);
boolean silent = pref1.getString("silentMode", "...");

to save vlue use onstoe or onPause methds

SharedPreferences pref2 = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = pref2.edit();
editor.putString("silentMode", "...");

That works for me fine and healthy

answered 2012-02-09T05:15:55.043

Your Answer