How to delete delayed messages before they arrive at a Handler?

moritz picture moritz · Dec 28, 2009 · Viewed 14.8k times · Source

My Problem is that I need to send messages with a delay of 1 second. The handler then initiates some action, you're getting the picture.

There are nevertheless some conditions in which the already sent message should be deleted ( before the second elapsed ) to prevent the handler from doing anything. I couldn't figure out how to do this ( or if it's even possible ), so If anyone of you has a clue, please let me know..

Answer

Romain Guy picture Romain Guy · Dec 28, 2009

There is nothing scary about the removeMessages() methods; they are perfectly safe. The framework relies heavily on these methods and they are used in many many places, especially in the default widgets (View, ListView, etc.) It's much much better than building a Handler that ignores specific messages. This is programming, don't go with your feelings :p