Android主线程
layout: post title: “2019-04-29-android 主线程” date: 2019-04-29 12:11:30 +0800
- Looper保存运行时.
public static void loop() { ... for (;;) {} ... }
如果停掉looper,会导致程序关闭. Caused by: java.lang.IllegalStateException: Main thread not allowed to quit.
-
android主线程和子线程有无本质区别 主线程接受重要事件.在ZygoteInit进行了提前注册.
-
ZygoteInit : java 入口初始化ZygoteServer ZygoteServer: 在主线程 循环监听fork请求,fork后执行ActivityThread ActivityThread: 初始化Looper,启动Activity
- ActivityThread 和 ActivityManagerService(SystemServer) https://blog.csdn.net/hzwailll/article/details/85339714 ``` java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gs.testnestscroll/com.example.gs.testnestscroll.MainActivity}: java.lang.IllegalStateException: Main thread not allowed to quit. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2841) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2919) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1637) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:176) at android.app.ActivityThread.main(ActivityThread.java:6656) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
```