设置初始时间
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
String thistime = df.format(new Date());SharedPreferences sharedPreferences = getSharedPreferences("industryInfo", Context.MODE_PRIVATE); //私有数据SharedPreferences.Editor editor = sharedPreferences.edit();//获取编辑器editor.putString(“retime”, thistime);//名称 ideditor.commit();//提交
检测是否刷新页面数据
SharedPreferences share = getSharedPreferences("industryInfo", Activity.MODE_PRIVATE);
String industryOne = share.getString("retime", "");//名称 获取id
Log.i("Lgq","sss==="+industryOne);SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
String nowtime = df.format(new Date());int distime= getDistanceTimemin(industryOne,nowtime);
if (distime>=5){SharedPreferences sharedPreferences = getSharedPreferences("industryInfo", Context.MODE_PRIVATE); //私有数据SharedPreferences.Editor editor = sharedPreferences.edit();//获取编辑器editor.putString("retime", nowtime);//名称 ideditor.commit();//提交//todo刷新
}
Log.i("lgq","sssss====="+distime+"...."+nowtime);
计算时间差方法getDistanceTimemin:https://blog.csdn.net/meixi_android/article/details/81868895