Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of removeCallbacks(Runnable r) in Handler in Android

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?

like image 654
AndroDev Avatar asked Jul 10 '12 13:07

AndroDev


Video Answer


2 Answers

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.

like image 99
Alex Lockwood Avatar answered Sep 28 '22 17:09

Alex Lockwood


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.

like image 34
Bill the Lizard Avatar answered Sep 28 '22 18:09

Bill the Lizard