I have a Java handler code which Im using in android to run a Timer…It runs awesome.
I need help to stop this timer(Handler) programmatically…Any simple method to stop this handler,when I exit from the activity in Android???
The Handler code section is :
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run()
{
// Do something after duration
}
}, duration);
How to stop this handler , so that the statement should not be executed after duration time. Or is there any other way to use a delay timer thread which can be handled by ourself???
Keep references to your Runnables, then call
removeCallbacks(runnable)on for each Runnable you’ve added to your handler to remove them.