when use defaultsharedpreferences save multiple data, found data covered. feel confused happened. expected values preferences
userid 2 authorizedheader bhlryxzpbjpsewthdmlu
and retrieved values
userid 2 authorizedheader 2
private static final string pref_authorized_query = null; private static final string pref_userid_query = null; public static string getstoreduseridquery(context context){ return preferencemanager.getdefaultsharedpreferences(context) .getstring(pref_userid_query, null); } public static string getstoredauthorizedquery(context context){ return preferencemanager.getdefaultsharedpreferences(context) .getstring(pref_authorized_query, null); } public static void setstoredquery(context context, string userid, string authorizedheader){ preferencemanager.getdefaultsharedpreferences(context) .edit() .putstring(pref_authorized_query, authorizedheader) .putstring(pref_userid_query, userid) .apply(); }
you using values null
both keys mean there 1 key i.e. null
override each other (pref_userid_query
on write previous values saved null
key)
so give them values
private static final string pref_authorized_query = "authorized"; private static final string pref_userid_query = "userid";
you can imagine like
preferencemanager.getdefaultsharedpreferences(context) .edit() .putstring("null", authorizedheader) .putstring("null", userid) // there 1 key .apply();
Comments
Post a Comment