Android 设置定时刷新页面数据,最小自动刷新时间

设置初始时间

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);//名称 id
  editor.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);//名称 id
    editor.commit();//提交
   //todo刷新
}
Log.i("lgq","sssss====="+distime+"...."+nowtime);

计算时间差方法getDistanceTimemin:https://blog.csdn.net/meixi_android/article/details/81868895

猜你喜欢

转载自blog.csdn.net/meixi_android/article/details/82491069
今日推荐