在特定时间重新启动活动



我正在开发一个应用程序,我需要在特定时间刷新/重新启动我的菜单页面活动。 例如下午 12 点。我怎样才能实现它。注意:如果用户在中午 12 点之前使用旧菜单使用我的应用程序,并且他在使用我的应用程序时已经过了中午 12 点的时间,则菜单页面需要在中午 12 点重新启动。如果应用已关闭,则应用无需重新启动。这是当客户在中午 12 点之前和下午 12 点之后使用我的应用程序时,因为我的菜单在下午 12 点之后发生了变化。所以用户需要在中午 12 点之后看到更新的菜单

这肯定会起作用,100%...

final long delayMillis=1000;
Handler h=null;
Runnable r;

in onCreate()

h=new Handler(Looper.getMainLooper());
    r = new Runnable() {
           public void run() {
               //current time
               Calendar c = Calendar.getInstance(); 
                int hour = c.get(Calendar.HOUR_OF_DAY);
                int min=c.get(Calendar.MINUTE);
                int sec=c.get(Calendar.SECOND);
                String currenttime= String.valueOf(hour)+" : "+String.valueOf(min)+" : "+String.valueOf(sec);

             //comparing current time with 12:00pm
               if(currenttime.equals("12 : 0 : 0")){
                 //restarting the activity
                   Intent intent = getIntent();
                   finish();
                   startActivity(intent);
               }

            h.postDelayed(this, delayMillis);
        }
      };
    h.post(r);

万事如意..

最新更新