Android source code-the message processing mechanism of the application

Source: Internet
Author: User

The Android application creates a message queue when each thread is started. The life cycle of a thread is divided into two phases: creating a message queue and entering a message loop.

Message loops are divided into: Send messages and process messages.

The Android system uses the MessageQueue, Looper, and handler three classes to implement the message processing mechanism for Android applications.

messagequeue--describing Message Queuing

looper--Creating message Queues

handler--sending messages, processing messages

Creating thread Message Queuing procedures

Call the Looper class static member function Preparemainlooper or prepare to create;

Create MessageQueue object, save in Mqueue;

MessageQueue in the process of creation, call the Nativeinit method to create a Nativemessagequeue object in the C + + layer;

Android_os_messagequeue_nativeinit method is implemented to create nativemessagequeue;

Nativemessagequeue creates a Looper object for the C + + layer during the creation process;

A pipeline is created during the Looper object creation process for the C + + layer.

Android source code-the message processing mechanism of the application

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.