java.lang.Object | |
↳ | android.os.Handler |
Class Overview
A Handler allows you to send and process Message
and Runnable objects associated with a thread'sMessageQueue
. 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.
mHandler = new Handler(){
public void handleMessage(Message msg){
//int android.os.Message.what
//User-defined message code so that the recipient can identify what this message is about.
switch(msg.what){
case UPDATE_TEXT:
mTextView.setText("text changed");
break;
default:
break;
}
}
};
public final boolean sendMessage(Message msg)Added inAPI level 1
Pushes a message onto the end of the message queue after all pending messages before the current time. It will be received inhandleMessage(Message)
, in the thread attached to this handler.
Returns
- 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.
Message mMessage = Message.obtain(mHandler, UPDATE_TEXT);
//Pushes a message onto the end of the message queue after all pending messages before the current time.
mHandler.sendMessage(mMessage);
java.lang.Object | |
↳ | android.os.Looper |
Class Overview
Class used to run a message loop for a thread. Threads by default do not have a message loop associated with them; to create one, callprepare()
in the thread that is to run the loop, and thenloop()
to have it process messages until the loop is stopped.
Most interaction with a message loop is through the Handler
class.