level 10
我在做一个抽奖功能:
功能是每天可以免费抽一次奖。
问题是怎么判断距离上次抽奖已经有24小时?
1,不用服务器。
2017年04月09日 06点04分
1
level 13
本地存储上次时间
用SharedPreferences
时间是long类型
启动软件可以获取上次时间 转换成long
当前时间相减 大于 24*1000*60*60就是一天
抽奖后吧当前时间在存进去
2017年04月09日 06点04分
4
1000是什么意思呢?
2017年04月09日 08点04分
level 12
开源库achce,可以实现定时存储。判断其空否即可
2017年04月09日 08点04分
6
不是很复杂,就用不着让库上场了
2017年04月09日 09点04分
level 10
private void init() {
//获取当前时间戳
timeGetTime = new Date().getTime();
//储存当前时间戳
SharedPreferences mySharedPreferences = getSharedPreferences("test", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = mySharedPreferences.edit();
editor.putLong("intsj", timeGetTime);//("名字","内容")
editor.commit();
Toast.makeText(this, "当前时间戳如下:\n" + timeGetTime,
Toast.LENGTH_LONG).show();
}
//读取数据函数
public void onClick_ReadData() {
//获取当前时间戳
timeGetTime = new Date().getTime();
//获取上次储存的时间戳
SharedPreferences sharedPreferences = getSharedPreferences("test", Activity.MODE_PRIVATE);
long intsj = sharedPreferences.getLong("intsj", 0);
intsj = timeGetTime - intsj;//当前时间timeGetTime减去上次储存时间intsj
if (intsj > 86400000) {
Toast.makeText(this, "已经24小时了",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "还没24小时" + intsj,
Toast.LENGTH_LONG).show();
}
}
2017年04月09日 09点04分
8