Android系统消息分发体系
Handler、Looper、Message、MessageQueue之间的关系(基于Android API 26) 安卓系统设计的消息分发体系,不仅在应用层广泛应用;而且在底层也是使用这个体系,与Binder一起进行消息分发,因此熟悉这个体系是十分必要的。 1、ActivityThread初始化时,执行它的main方法,通过Looper.prepareMainLooper方法,初始化一个Looper对象(代码有省略),同时初始化ActivityThread,接着执行Looper的loop方法。 public static void main(String[] args) { Looper.prepareMainLooper(); ActivityThread thread = new ActivityThread(); thread.attach(false); if (sMainThreadHandler == null) { sMainThreadHandler = thread.getHandler(); } if (false) { Looper.myLooper().set...