Preliminary study on android-asynchronous message processing mechanism

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.