- 从
ActivityThread.java中的main()方法开始,初始化Looper,实例化ActivityThread,发送创建Application的消息,开启Looper的无限循环状态,接收消息。 - 发送创建Application的消息:通过Binder与AMS通信,通知AMS发送H.BIND_APPLICATION消息到主Handler中,主Handler接收到消息后,调用
handleBindApplication()方法,初始化Instrumentation,通过Instrumentation调用Application的onCreate()方法从而创建了Application。 - 当Application初始化完成后,系统会根据Manifests中配置的启动Activity发送一个Intent去启动相应的Activity。通过AMS发送H.LAUNCH_ACTIVITY消息到主Handler中,主Hnadler接收到消息后,调用
handleLaunchActivity()方法,该方法通过Instrumentation调用Activity的onCreate()创建activity。
