Android MessageQueue Mechanism
Core classes:
Handler – the operator, user apps use this to operate the Messages: send messagewith postRunnable, sendMessage etc. and process Messages in handleMessage.
Message – the container for the data andinformation
MessageQueue – the internal containers forMessages. User apps are not allowed to operate it directly. It is operatedinternally by Handler
Looper – the rules which let thread rununtil stop() is called. This is much like use a while (true) in the thread tomake it run as long as you wish
The general Message processing would be like this:
1. make the thread (either main thread or user-created thread) can loop,with calling Looper.prepare();
2. Send the Message with Handler.
3. OverrideHandler.handleMessage to process the Message;
4. Stop the looper by callingLooper.stop(), then thread will exit.
本文深入探讨了Android中消息队列机制的核心组件及其工作流程,包括Handler、Message、MessageQueue和Looper的作用与交互,详细解释了消息处理的一般过程。
869

被折叠的 条评论
为什么被折叠?



