1:消息机制流程
sendMessage ->MessageQueue.enqueueMessage :添加消息
Looper.loop->MessageQueue.next->dispathMessage->hadlerMessage;
2:主线程可以new Handler 因为 在ActivityThread main方法里面已经初始化了Looper;
3:子线程如何调用handler ;
Looper.prepare(); new Handler(){ handlerMessage(){ } }
Looper.loop();
在处理完消息之后要调用looper.quit()来唤醒线程,否则会进入等待状态;
Looper阻塞原理:MessageQueue.nativePollOnce方法,如果没有Message会通知底层进入等待状态;
Looper唤醒原理:MessageQueue.nativeWake唤醒线程,通知工作