Introduction to Android handler mechanism

Source: Internet
Author: User

The concept of 1,handler
What is Handler used for?
1) Perform scheduled tasks, perform certain tasks at scheduled times, and can simulate timers

2) Inter-thread communication. When the Android app starts, a main thread is created, and the main thread creates a
Message Queuing to process various messages. When you create a child thread, you can get the parent thread in your child thread
Creates a handler object that can be used to send messages to the parent thread's message queue. Because Android
Requires that the interface be updated in the UI thread, so that the interface can be updated in other threads by this method.

Role Description:
1) Looper: A thread can produce a Looper object that manages this line thread the message Queue

2) Handler: You can construct Handler objects to communicate with Looper in order to push new messages into the message queue, or
Receives Looper messages sent from the message Queue.

3) Message queue (Message Queuing): Is the message used to hold the thread into place.

4) Thread: 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 Message Queue data structure. In your application,
You can define Handler subcategories to receive messages sent by Looper.

2,handler the execution of the process

Each handler corresponds to a thread, and the message sent handler the child thread into the message queue, which is then distributed to handler processing by Looper.

Introduction to Android handler 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.