您的位置:首页 > 移动开发 > Android开发

ANDROID 学习笔记(二) 用户登陆问题 TOKEN SESSION 缓存

2014-11-20 00:00 573 查看
摘要: android token 缓存

首先介绍TOKEN 缓存问题

写个工具类 里面放入

/*
* 获取缓存的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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐