1. First Looper.prepare () saves an looper instance in this thread, and then holds a MessageQueue object in the instance, because Looper.prepare () can only be called once in a thread. So MessageQueue will only exist in one thread.
2. Looper.loop () causes the current thread to enter an infinite loop, which reads the message from the MessageQueue instance and then callbacks the Msg.target.dispatchMessage (msg) method.
3, handler the construction method, will first get the current thread saved Looper instance, and Looper instance in the MessageQueue want to associate.
4, Handler SendMessage method, will give the target of MSG to handler itself, and then add MessageQueue.
5. When constructing handler instances, we override the Handlemessage method, which is the method that Msg.target.dispatchMessage (msg) eventually calls.
In activity, we did not show calls to the Looper.prepare () and Looper.loop () methods, why handler can be created successfully,
This is because in the activity's startup code, the Looper.prepare () and Looper.loop () methods have been called in the current UI thread
Produces a message object that can be new or use the Message.obtain () method;
However, it is more recommended to use the obtain method, because the message internally maintains a message pool for reuse of message, and avoids using new to reallocate memory.
Reference: Android handlerthread Full parsing
Links between Android hander, Looper, and message