How to stop the Timer in android? [closed] How to stop the Timer in android? [closed] android android

How to stop the Timer in android? [closed]


     CountDownTimer waitTimer;     waitTimer = new CountDownTimer(60000, 300) {       public void onTick(long millisUntilFinished) {          //called every 300 milliseconds, which could be used to          //send messages or some other action       }       public void onFinish() {          //After 60000 milliseconds (60 sec) finish current           //if you would like to execute something when time finishes                 }     }.start();

to stop the timer early:

     if(waitTimer != null) {         waitTimer.cancel();         waitTimer = null;     }


and.. we must call "waitTimer.purge()" for the GC. If you don't use Timer anymore, "purge()" !! "purge()" removes all canceled tasks from the task queue.

if(waitTimer != null) {   waitTimer.cancel();   waitTimer.purge();   waitTimer = null;}


In java.util.timer one can use .cancel() to stop the timer and clear all pending tasks.