Android-Asynchronous Message Processing Mechanism preliminary, android-asynchronous mechanism

Source: Internet
Author: User

Android-Asynchronous Message Processing Mechanism preliminary, android-asynchronous mechanism

Android asynchronous Message processing consists of four parts: Message, Handler, MessageQueue, and logoff.

Message:A message transmitted between threads. It can carry a small amount of information internally and is used to exchange data between different threads. The arg1 and arg2 fields can be used to carry some integer data. shiyongobj carries an Object.

Handler: The processor, mainly used to send and process messages. The sendMessage () method is used to send information. After a series of processing operations, it is passed to the handleMessage () method.

MessageQueue: Message Queue, mainly used to store all messages sent by Handler. This part of messages will always exist in the message queue and will be processed. Each thread has only one MessageQueue object.

Logoff: The MessageQueue manager in each thread. after calling the logoff loop () method, it will enter an infinite loop, as longMessageQueueIf a message exists, it is taken out and passed to the Handler's hanleMessage () method. Each thread also has only one logoff object.

The process of Asynchronous Message Processing Mechanism (taking changing the UI as an example ):

Create a Handler object in the main thread and rewrite the handlerMessage () method as needed. When the sub-thread performs UI operations, a Message object is created, which is sent out through the Handler object and added to MessageQueue for processing, logoff will always try to retrieve this Message from MessageQueue, and finally distribute it back to Handler's handleMessage () method.

Related Article

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.