In what order are messages and runnables handled by the handler?

From reading the documentation, HandlerI get a message that both messages are sent , and in the same message queue of the thread associated with this handler.

My question is: are they both processed in the order in which they are sent / sent?

For example, imagine that I have a myHandler handler and I am doing the following:

myHandler.post(runnable1);
myHandler.sendMessage(message1);
myHandler.post(runnable2);
myHandler.sendMessage(message2);

In what order will these runnables and messages be processed?

Will each of them be processed in the same order in which they were sent / sent? Are messages handled separately from runnables? Or is it harder, for example, messages with a higher priority than runnables?

+4
source share

Source: https://habr.com/ru/post/1667641/


All Articles