Introduction to Handler, logoff, and MessageQueue, loopermessagequeue
Handler, logoff, and MessageQueue constitute the most important message transmission and processing mechanism system in android.
Handler running principle
The message object in the message queue is FIFO ). Handler is responsible for adding the message object to the queue. The loose cyclator keeps retrieving the message object from the message queue and calls the handleMessage method of Handler to process the message. When no message object exists in the queue, logoff is in the waiting status (blocking)
Handler uses a small example: the user clicks the button to generate a message object and print the message content
1. Define the class to inherit the Handler, rewrite the handleMessage method, and generate the Handler object
2. Get and assign values to the Message object and send it to the Message queue.
3. logoff retrieves the message from the message queue and finds the corresponding Handler object.
4. logoff calls handleMessage of the Handler object to process messages