Question

I want to know what is the exact meaning of removeCallbacks(Runnable r) in Handler. I gone through its documentation and it simply says "Remove any pending posts of Runnable r that are in the message queue".

Now my question is if my message has already been started processing by my handler and in between if I call removeCallbacks, will it stop processing my half completed message? Or even if I call removeCallbacks the message which has already started processing by my handler (when I call post(Runnable r)) will be executed?

Était-ce utile?

La solution

Runnables should only be executed as they come out of the message queue, so if your message has already started processing it should not be effected by calling removeCallbacks. It should have already been removed, so it will continue processing.

Autres conseils

When you create a new Handler, it is bound to the thread / message queue of the thread that is creating it. From that point on, it will deliver messages and runnables to that message queue and execute them as they come out of the message queue. removeCallbacks simply removes those runnables who have not yet begun processing from the queue.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top