Raegtime Raegtime - 18 days ago 5
Android Question

Android SharedPreferences empty after commit

Why is in the following example the foo false?

mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
mPrefs.edit().putBoolean("myValue",true);
mPrefs.edit().commit();

boolean foo = mPrefs.getBoolean("myValue",false);

Answer

I think you have to write in this way

mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
mPrefs.edit().putBoolean("myValue",true).commit();

boolean foo = mPrefs.getBoolean("myValue",false);
Comments