Official description of Android Handler

Official API documentation: https://developer.android.google.cn/reference/android/os/Handler

Handler allows you to send and process Message and Runnable objects associated with a thread's MessageQueue. Each Handler instance is associated with a single thread and that thread's message queue. When a new Handler object is created, it will be bound to the thread that created it and the thread's message queue, then the Handler will deliver and add messages to the message queue, and process and execute them in the message queue.

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.

Methods of dispatching messages include:

post(Runnable r)  Add the Runnable object r to the message queue
postAtTime(Runnable r, long uptimeMillis)  Add the Runnable object r to the message queue and execute it at the time set by uptimeMillis
postDelayed(Runnable r, long delayMillis)  Add the Runnable object r to the message queue and execute it after delayMillis
sendEmptyMessage(int what)  Send an empty message, containing only the what attribute
sendMessage(Message msg)  Add a message to the end of the queue of waiting messages
sendMessageAtTime(Message msg, long uptimeMillis)  Adds a message to the end of the queue of waiting messages at the specified time uptimeMillis
sendMessageDelayed(Message, long)  Add a message to the end of the queue of waiting messages after a delay of delayMillis

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325263590&siteId=291194637