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     }
View Code

相关文章:

  • 2021-12-20
  • 2021-11-15
  • 2022-12-23
  • 2021-08-28
  • 2021-08-14
猜你喜欢
  • 2022-12-23
  • 2022-02-08
  • 2022-12-23
  • 2021-11-29
  • 2021-09-02
  • 2021-06-09
相关资源
相似解决方案