android - Shared Preferences not persistent after app restart -



android - Shared Preferences not persistent after app restart -

i found answers here , tried solutions, still shared prefs not persistent.

here's code:

public static void setactivated(boolean activated) { sharedpreferences sp = utils.getcontext().getsharedpreferences( user_prefs, context.mode_private); sharedpreferences.editor editor = sp.edit(); editor.putboolean(asd, activated); editor.commit(); } public static boolean isactivated() { sharedpreferences sp = utils.getcontext().getsharedpreferences(user_prefs, context.mode_private); homecoming sp.getboolean(asd, true); }

i've tried also:

editor.clear(); editor.put .. editor.commit();

i've tried with

editor.apply();

i tried both .apply() , .commit() , no luck.

another thought seek using different mode files:

...getsharedpreferences(user_prefs, context.mode_multi_process);

the problem values saved not persistent. if close app , re-open values wrong.

does have ideas? mention problem on devices, illustration htc 1 s, samsung galaxy s3 (i tested on different s3 , worked perfectly).

edit: phone call save on button click listener , phone call isactivated when load fragment (after onviewcreated()).

thanks!

public abstract sharedpreferences.editor clear ()

added in api level 1 mark in editor remove values preferences. 1 time commit called, remaining preferences have defined in editor. note when committing preferences, clear done first, regardless of whether called clear before or after set methods on editor. returns returns reference same editor object, can chain set calls together.

in user preferences class getting null value on other strings , code this:

sharedpreferences sp = utils.getcontext().getsharedpreferences( user_prefs, context.mode_private); sharedpreferences.editor editor = sp.edit(); if (session != null && !"".equals(session)) { sessionid = session; editor.putstring(session, sessionid).commit(); } else { sessionid = null; editor.clear().commit(); }

the editor.clear() resetting other commits!

android save preferences shared persistent

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -