ANDROID学習ノート(二)ユーザ登録問題TOKEN SESSIONキャッシュ
1272 ワード
まずTOKENキャッシュの問題について紹介します
工具類を書いて入れる
ANDROID APIの説明:
Interface for accessing and modifying preference data returned by
簡単な説明:データを修正し終わって、必ず提出して、データの多重保存方式があります
詳細はAPIを参照
工具類を書いて入れる
/*
* token
*/
public static String getCachedToken(Context context){
return context.getSharedPreferences(APP_ID, context.MODE_PRIVATE).getString(KEY_TOKEN, null);
}
/*
* token
*/
public static void cacheToken(Context context, String token){
Editor e = context.getSharedPreferences(APP_ID, context.MODE_PRIVATE).edit();
e.putString(KEY_TOKEN, token);
e.commit();
}
ANDROID APIの説明:
Interface for accessing and modifying preference data returned by
getSharedPreferences(String, int)
. For any particular set of preferences, there is a single instance of this class that all clients share. Modifications to the preferences must go through an SharedPreferences.Editor
object to ensure the preference values remain in a consistent state and control when they are committed to storage. Objects that are returned from the various get
methods must be treated as immutable by the application. 簡単な説明:データを修正し終わって、必ず提出して、データの多重保存方式があります
MODE_PRIVATE
MODE_WORLD_READABLE
MODE_WORLD_WRITEABLE
MODE_MULTI_PROCESS
詳細はAPIを参照