The difference between Handler.dispatchMessage(msg) and Handler.sendMessage(msg)
mHandler.dispatchMessage(msg)
is like directly calling handleMessage(Message msg)
and I don't know when that would be useful. The point of Handlers is the ability to send messages to other threads. That's what you do with sendMessage
.
Edit: as you can see it just calls handleMessage()
for you.
/**
* Handle system messages here.
*/
public void dispatchMessage(Message msg) {
if (msg.callback != null) {
// callback = the Runnable you can post "instead of" Messages.
msg.callback.run();
} else {
if (mCallback != null) {
if (mCallback.handleMessage(msg)) {
return;
}
}
handleMessage(msg);
}
}
If You Call the Handler.dispatchMessage()
in the Main Thread Then The Message is processed in Main Thread.
If You Call The Handler.dispatchMessage()
in the Worker Thread Then The Message is Processed in Worker Thread.
When You Call Handler.sendMessage(msg)
The Message is Processed in the Thread Which Created The Handler.