android28 startActivity启动流程分析(一)--从本地到AMS调用参数对照

用户调用Activity:startActivity()----->Activity:startActivityForResult()-->Instrumentation:execStartActivity()-->远程AMS

Instrumentation.java

public ActivityResult execStartActivity(
        Context who, IBinder contextThread, IBinder token, Activity target,
        Intent intent, int requestCode, Bundle options) {
......
int result = ActivityManager.getService()
    .startActivity(whoThread, who.getBasePackageName(), intent,
            intent.resolveTypeIfNeeded(who.getContentResolver()),
            token, target != null ? target.mEmbeddedID : null,
            requestCode, 0, null, options);
}

 调用  ActivityManagerService.java

public final int startActivity(IApplicationThread caller, String callingPackage,
        Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode,
        int startFlags, ProfilerInfo profilerInfo, Bundle bOptions) {
    return startActivityAsUser(caller, callingPackage, intent, resolvedType, resultTo,
            resultWho, requestCode, startFlags, profilerInfo, bOptions,
            UserHandle.getCallingUserId());
}

execStartActivity()-->Ams startActivity()方法调用的参数对照表:

这些参数还是挺重要的,Ams以后的调用流程都会用到这些参数,但是Ams里面的部分新参数名字不是很容易理解,所以这里特别列出来。
 

ActivityManagerService.java

        startActivity()

Instrumentatiaon.java

    execStartActivity()

释义
caller whothread Binder,可以看成应用主线程的标识
callingPackage who.getBasePackageName() 应用包名
intent intent  
resolvedType

intent.resolveTypeIfNeeded

(who.getContentResolver())

如果intent的component不为空,这里返回intent的mType字段,理解为null就可以
resultTo token Binder,Activity的mToken字段,远程ActivityRecord在本地的标识
resultWho target != null ? target.mEmbeddedID : null mEmbeddedID 字段来自于ActivityThread的内部类ActivityClientRecord类的embededId字段,可以理解为应用本地维护acitivity的标识
requestCode requestCode 如不设置,默认为-1
startFlags 0  
profilerInfo null  
bOptions options  

resultTo和resultWho这2个参数,虽然名字包含result,但是并不代表要跳转的目标acticity,而且用来标识startActivityForResult,当设置requestcode>0,需要从跳转的Activity获取返回值重新返回此源Activity时,对当前源Activity的标识和记录。

你可能感兴趣的:(android28 startActivity启动流程分析(一)--从本地到AMS调用参数对照)