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