伊谢尔伦2017-04-17 13:32:322楼
1.
所有 修改系统时间的问题都可以通过添加 nanoTime 验证来解决.
System.nanoTime();
/**
* Returns the current timestamp of the most precise timer available on the
* local system, in nanoseconds. Equivalent to Linux's {@code CLOCK_MONOTONIC}.
*
*
This timestamp should only be used to measure a duration by comparing it
* against another timestamp on the same device.
* Values returned by this method do not have a defined correspondence to
* wall clock times; the zero value is typically whenever the device last booted.
* Use {@link #currentTimeMillis} if you want to know what time it is.
*/
public static native long nanoTime();
注意nanoTime返回的不是UTC时间,是开机以后经过的时间.不受系统时间影响.
2.
在实际项目中,我现在的处理方案是,根本就不记录expires.
在网络层会封装各种错误,token失效会触发一个401错误
在错误分发器上,我主动拦截该错误并发起一个事件(REFRESH_TOKEN)
用Event Dispatch框架(EventBus,otto之类的)在上层接受该事件,并把用户直接导向登录界面或弹出Alert确认框