Android: Principle of Handler mechanism

Define a Handler in the main thread, encapsulate the Message in the child thread, (and bring back the data that needs to be returned with the Obj in the Message,)
use the sendMessage method of the Handler to send the message, and call the SendMessageDelayed method at the bottom of the sendMessage method ,
And the SendMessageDelayed method calls the sendMessageAttime method at the bottom, and the sendMessageAtTime method calls the handler
’s enqueueMessage method to send the message to the message queue Messagequeue at the bottom , while the Handler’s enqueueMessage method calls the
Messagequeue’s enqueueMessage() method to push the message into the queue. Looper provides power. By calling the loop() method,
there is an infinite for loop in the loop() method and the next() method of MessageQueue is called to transport the message to the main thread. The
corresponding handler is found through the target attribute, and the dispatchMessage method of the handler will Message distribution (call back the handleMessage method
).

Guess you like

Origin blog.csdn.net/u010256329/article/details/51832329