An explanation of the mechanism and usage of handler in Android

Source: Internet
Author: User

Overview:

Many Android beginners to Android handler is not very clear, in fact, Google reference the Windows message processing mechanism,

A similar message-handling mechanism was implemented in the Android system. Before introducing the handler mechanism, here are a few concepts to understand:

1. Message

Messages, which are understood as data units for inter-thread communication. For example, a background thread that needs to update the UI after processing the data can send a message containing the update information to the UI thread.

2. Message Queue

Message Queuing, used to store messages published through Handler, followed by FIFO execution.

3. Handler

Handler is the primary processor for message, which is responsible for adding messages to message queues and processing messages in message queues.

4. Looper

The circulator, acting as a bridge between the message queue and the handler, loops out the message within the message queue and delivers it to the corresponding handler for processing.

5. Threads

The UI thread is usually the main thread, and the Android launcher will create a message Queue for it.

Each thread can contain a Looper object and a MessageQueue data structure. In your application, you can define handler subcategories to receive messages sent by Looper.

Okay, here's the text ~

An explanation of the mechanism and usage of handler in Android

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.