源码 片段1 如下: /** * Pushes a message onto the end of the message queue after all pending messages
* before the current time. It will be received in {@link #handleMessage},
* in the thread attached to this handler.
*
* @return 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.
*/
publicfinal booleansendMessage(Message msg) {
returnsendMessageDelayed(msg, 0);
} 再看handler.obtainMessage()源码 片段2 如下: /** * Returns a new {@link android.os.Message Message} from the global message pool. <BR> * More efficient than creating and allocating new instances. <BR> * The retrieved message has its handler set to this instance <BR> * (Message.target == this).
* If you don"t want that facility, just call Message.obtain() instead.
看一下Message.obtain(Hanlder h) 的源码 代码片段3如下: /** * Same as {@link #obtain()}, but sets the value for the <em>target</em> member on the Message return * ed.
* @param h Handler to assign to the returned Message object"s <em>target</em> member.
* @return A Message object from the global pool.
*/
publicstatic Message obtain(Handler h) {
Message m = obtain();
m.target = h;
returnm; } 再看 sendToTarget() 源码 代码片段4 如下: /** * Sends this Message to the Handler specified by {@link #getTarget}.
* Throws a null pointer exception if this field has not been set.
/** * Returns a new {@link android.os.Message Message} from the global message pool. More efficient than * creating and allocating new instances. The retrieved message has its handler set to this instance (Message.target == this). * If you don"t want that facility, just call Message.obtain() instead. */