0 votes
1 view
in Java by (2.6k points)

I have a Handler from my sub-Activity that was called by the main Activity. This Handler is used by sub-classes to postDelay some Runnables, and I can't manage them. Now, in the onStop event, I need to remove them before finishing the Activity (somehow I called finish(), but it still call again and again). Is there anyway to remove all callbacks from a Handler?

1 Answer

0 votes
by (46.1k points)

In my practice calling, this worked exceptionally!

handler.removeCallbacksAndMessages(null);

In the docs for removeCallbacksAndMessages, it says...

Discard any pending posts of callbacks and sent notes whose obj is token. If the token is null, all callbacks and messages will be eliminated.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...