Send an android.os.Message whose what is 0 and then remove it, which unexpectedly removes all posted Runnables
I write a Runnable and post it to the main thread, however the Runnable is not executed.
1 2 3 4 5 6
After posting the Runnable, someone executes the following code:
and it not only removes the custom message but also removes all posted Runnables in the MessageQueue. The reason is that android.os.Handler wraps every posted Runnable in an android.os.Message whose what is 0 which conflicts with the what value of the custom message.
1 2 3 4 5 6 7 8 9 10 11
Never use 0 as the what value of custom messages
The source code of android.os.Handler, android.os.Message and android.os.MessageQueue