Reputation: 28439
Handler h = new Handler();
h.postDelayed(new Runnable(){...}, 5000);
Is there any way to clear this prior to the 5 second expiration or does the Handler not have a public method that I can use to null out the anonymous Runnable
?
Upvotes: 1
Views: 530
Reputation: 33515
Is there any way to clear this prior to the 5 second expiration
I think this should make a trick (but Runnable needs to be not anonymous):
handler.removeCallBacks(runnable);
For anonymous runnables should work:
handler.removeCallbacksAndMessages(null);
What source says:
Remove any pending posts of callbacks and sent messages whose obj is token. If token is null, all callbacks and messages will be removed.
Upvotes: 4