Official API Document: Https://developer.android.google.cn/reference/android/os/Handler
Handler allows you to send and process message and runnable objects associated with the MessageQueue of a thread. Each handler instance is associated with a single thread and Message Queuing for that thread. When a new handler object is created, it is bound to the message queue that created his thread and thread, and then handler passes the message and adds it to the message queue and processes and executes it in the message queue.
The handler has two main functions:
- Schedule a message or runnable to execute somewhere in a main thread;
- Schedule an action to be executed in a different thread.
The methods for dispatching messages include:
| Post (Runnable R) |
Add the Runnable object R to the message queue |
| Postattime (Runnable R, Long Uptimemillis) |
Adds the Runnable object R to the message queue and executes at the time the Uptimemillis is set |
| Postdelayed (Runnable R, Long Delaymillis) |
Adds the Runnable object R to the message queue and executes after a delay of Delaymillis |
| Sendemptymessage (int what) |
Send an empty message containing only the What property |
| SendMessage (Message msg) |
Add a message to the end of the queue for the message you are waiting for |
| Sendmessageattime (Message msg, long Uptimemillis) |
Adds a message to the end of the queue of a waiting message at a specified time Uptimemillis |
| Sendmessagedelayed (Message, long) |
Add a message to the end of the queue of a waiting message after the delay Delaymillis |
Android Handler Official description