美文网首页
Android 中 startActivity() 执行流程

Android 中 startActivity() 执行流程

作者: 雁过留声_泪落无痕 | 来源:发表于2017-10-12 18:39 被阅读0次

    以 sdk 23 源码为例:

    Activity.java:
    startActivity(Intent)
    ==> startActivity(Intent, Bundle)
    ==> startActivityForResult(Intent, int, Bundle)

    Instrumentation.java:
    ==> execStartActivity(Context, IBinder, IBinder, Activity, Intent, int, Bundle)

    ActivityManagerNative.java:
    ==> getDefault() 返回 ActivityManagerProxy 对象
    ==> ActivityManagerProxy#startActivity(...)
    调用 mRemote.transact(...) 进行 IPC 调用
    ==> ActivityManagerNative.onTransact(int, Parcel, Parcel, int)

    ActivityManagerService.java:
    ==> startActivity(...)
    ==> startActivityAsUser(...)

    ActivityStackSupervisor.java:
    ==> startActivityMayWait(...)
    ==> startActivityLocked(...)
    ==> startActivityUncheckedLocked(...)

    ActivityStack.java:
    ==> resumeTopActivityLocked(...)
    ==> resumeTopActivityInnerLocked(...)

    ActivityStackSupervisor.java:
    ==> startSpecificActivityLocked(...)
    ==> realStartActivityLocked(...)
    调用 app.thread.scheduleLaunchActivity(...)

    ApplicationThreadNative.java:
    ==> ApplicationThreadNative$ApplicationThreadProxy#scheduleLaunchActivity(...)
    调用 mReote.transact(...) 进行 IPC 调用
    ==> ApplicationThreadNative#onTransact(...)

    ActivityThread.java
    ==> ActivityThread$ApplicationThread#scheduleLaunchActivity(...)
    通过 Handler 发送消息 LAUNCH_ACTIVITY
    ==> ActivityThread$H#handleMessage(...)
    ==> handleLaunchActivity(...)
    ==> performLaunchActivity(...)
    创建 Activity 实例并调用 attach(...) 方法,
    同时调用 Instrumentation#callActivityOnCreate() 方法,

    Activity.java:
    ==> performCreate(...)
    ==> onCreate(...)

    至此,你终于看到了你熟悉的 onCreate(...) 方法!

    相关文章

      网友评论

          本文标题:Android 中 startActivity() 执行流程

          本文链接:https://www.haomeiwen.com/subject/mduoyxtx.html