How to remove a runnable from a handler object added by postDelayed?

Bruce Lee picture Bruce Lee · Sep 2, 2010 · Viewed 50.6k times · Source

I have an "open" animation and am using Handler.postDelayed(Runnable, delay) to trigger a "close" animation after a short delay. However, during the time between open and close, there is possibly another animation triggered by a click.

My question is, how would I cancel the "close" animation in the handler?

Answer

Cristian picture Cristian · Sep 2, 2010

Just use the removeCallbacks(Runnable r) method.