1
當我使用defaultsharedpreferences保存多個數據時,我發現數據被覆蓋。我對發生的事情感到困惑。從喜好無法從getdefaultsharedpreferences獲得正確的結果
userId is 2
authorizedHeader is bhlrYXZpbjpseWthdmlu
和檢索值
userId is 2
authorizedHeader is 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();
}
謝謝!有用。那麼關鍵是使用字符串的值? – borderwing
確切地說,你明白了,歡迎 –