I have a timer that forces the function to run every minute, per minute. When the action is paused, the timer continues. I do not want it to work, as it is not necessary.
If it works on suspension, how can I prevent it?
A piece of chalk.
In onCreate () I have
//Respond to clock changing every minute, on the minute myTimer = new Timer(); GregorianCalendar calCreationDate = new GregorianCalendar(); calCreationDate.add(Calendar.MILLISECOND, (-1*calCreationDate.get(Calendar.MILLISECOND))); calCreationDate.add(Calendar.SECOND, -1*calCreationDate.get(Calendar.SECOND)); calCreationDate.add(Calendar.MINUTE, 1); //Update every one minute myTimer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { timerMethod(); } }, calCreationDate.getTime(), 60000);
Inside the class (outside onCreate ()) I have:
//Update the clock every minute protected void timerMethod() { this.runOnUiThread(Timer_Tick); } //end TimerMethod private Runnable Timer_Tick = new Runnable() { public void run() { int intTpHour = tpTimePicker.getCurrentHour(); int intTpMinute = tpTimePicker.getCurrentMinute(); displayMyTime(intTpHour, intTpMinute); } }; //end Runnable Timer Tick
source share