I made a vegetable machine app for the wholesale market. I hope it can automatically exit the main interface to the login interface at 12 o ‘clock in the evening and realize onCreate() by using the Timer Timer.

SimpleDateFormat nowtime = new SimpleDateFormat("hh:mm:ss"); Date date = new Date(); mTimer = new Timer(); mTimer.schedule(new TimerTask() { @Override public void run() { date.setTime(System.currentTimeMillis()); // log.e ("wy"," current time: "+nowtime.format(date)); // 23:59:59 if(nowtime.format(date).equals("23:59:59")){ startActivity(new Intent(TradeActivity.this,LoginActivity.class)); finish(); }}}, 0100, 0);Copy the code

In onDestory

mTimer.cancel();
Copy the code