If you check Message.java code for example from here you will see
//Sends this Message to the Handler specified by getTarget().
public void sendToTarget() {
target.sendMessage(this);
}
In other words, sendToTarget()
will use a previously specified Handler
and invoke its sendMessage()
If you look for the obtain()
method you will see:
public static Message obtain() {
synchronized (sPoolSync) {
if (sPool != null) {
Message m = sPool;
sPool = m.next;
m.next = null;
m.flags = 0; // clear in-use flag
sPoolSize--;
return m;
}
}
return new Message();
}
The explanation provided is also very good:
Return a new Message instance from the global pool. Allows us to avoid
allocating new objects in many cases.
Doing the same for obtain(Handler h)
:
public static Message obtain(Handler h) {
Message m = obtain();
m.target = h;
return m;
}
You can confirm that obtain(Handler h)
really is obtain()
with the addition of setting the target Handler
Same as obtain(), but sets the value for the target member on the Message returned.
There are several other overloads , just check Message.java and search for "obtain"
obtain(Message orig)
obtain(Handler h, Runnable callback)
obtain(Handler h, int what)
obtain(Handler h, int what, Object obj)
obtain(Handler h, int what, int arg1, int arg2)
obtain(Handler h, int what, int arg1, int arg2, Object obj)
- ...
Hope this helps, cheers!