Android's asynchronous message processing consists of 4 parts, message, Handler, MessageQueue, and Looper
Message : messages passed between threads, which can carry a small amount of information inside, to exchange data between different threading. You can use the Arg1 and Arg2 fields to carry some shaping data, Shiyongobj carry a single Object object
Handler: A processor that is used primarily to send and process messages. The SendMessage () method is used to send information, which is passed to the Handlemessage () method after a series of tossing and processing.
MessageQueue: Message Queuing, which is used primarily to hold all messages sent through handler, which is always present in the message queue and waiting to be processed. Each thread will have only one MessageQueue object.
Looper: MessageQueue's housekeeper in each thread, after calling the Looper loop () method, enters an infinite loop, as long as there is a message in MessageQueue . will be removed and passed into the Hanlemessage () method of the handler. Each thread will also have only one Looper object.
Flow of asynchronous message processing mechanisms (in the case of changing the UI):
Create a handler object in the main thread and override the Handlermessage () method as required. When a child thread makes a UI operation, it creates a message object that sends it through the handler object and joins it to the MessageQueue waiting to be processed. Looper will always try to remove this message from the MessageQueue and distribute it back to the handler Handlemessage () method.
Preliminary study on android-asynchronous message processing mechanism