1.handler,looper,messagequeue三者之间的关系以及各自的角色?
答:MessageQueue就是存储消息的载体,Looper就是无限循环查找这个载体里是否还有消息。Handler就是创建的时候 会使用looper来构建这个消息循环。
handler的主要功能就是 将一个任务切换到某个指定的线程中去执行。
2.为何android 无法在子线程更新ui?
答:都知道 更新ui 实际工作都是在viewrootimpl这个类里面去做的。他的源码里有下面这样一个函数:
1 void checkThread() { 2 if (mThread != Thread.currentThread()) { 3 throw new CalledFromWrongThreadException( 4 "Only the original thread that created a view hierarchy can touch its views."); 5 } 6 }