android.os.Handler

android.os.handler

A 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 you create a new Handler, it is bound to the thread / message queue of the thread that is creating it -- from that point on, it will deliver messages and runnables to that message queue and execute them as they come out of the message queue.

There are two main uses for a Handler: (1) to schedule messages and runnables to be executed as some point in the future; and (2) to enqueue an action to be performed on a different thread than your own.

The send message versions allow you to enqueue a Message object containing a bundle of data that will be processed by the Handler's handleMessage(Message) method (requiring that you implement a subclass of Handler).
中文:sendMessage类的函数将message插入message队列,然后Handler调用函数handleMessage()去处理。

public final boolean sendEmptyMessage (int what)

Sends a Message containing only the what value.

Returns true if the message was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting.

public void handleMessage (Message msg)

Subclasses must implement this to receive messages.

参考

http://web.mit.edu/majapw/MacData/afs/sipb/project/android/docs/reference/android/os/Handler.html#handleMessage(android.os.Message)

posted @ 2017-08-21 15:52  xiulug  阅读(526)  评论(0编辑  收藏  举报