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

首先介绍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.

简要说明: 修改完数据,一定要提交,数据的有多重保存方式

详细解释见API

转载于:https://my.oschina.net/tacg/blog/346807

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值