Android 11(platfrom 30)APP启动流程(含Activity)核心点记录
Posted 安卓开发-顺
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android 11(platfrom 30)APP启动流程(含Activity)核心点记录相关的知识,希望对你有一定的参考价值。
前言:边分析,边记录 不断更新
场景一、从桌面点击APP图标进行启动
涉及到的核心进程:
step 1:
解析androidManifest文件 组装Intent对象
--> Activity --- startActivity
--> Activity --- startActivityForResult
--> Instrumentation --- execStartActivity
--- ActivityTaskManager.getService().startActivity 此处是通过Binder跨进程通信 去调用系统进 程SystemService 的ActivityMangerService 以下简称AMS
--> AMS --- startActivity
--> ActivityTaskManagerService --- startActivity 1043行
--> ActivityTaskManagerService --- startActivityAsUser 1068行
--> ActivityTaskManagerService --- startActivityAsUser 1077行
--- getActivityStartController().obtainStarter 这里得到了一个 ActivityStarter对象
--> ActivityStarter --- execute 628行
--> ActivityStarter --- executeRequest 835行 --- 1186行 startActivityUnchecked
--> ActivityStarter --- startActivityUnchecked 1512行
--> ActivityStarter --- startActivityInner 1587行
--> ActivityStarter --- startActivityInner 1587行 1731行
--> RootWindowContainer --- resumeFocusedStacksTopActivities 2285行
--> RootWindowContainer --- resumeFocusedStacksTopActivities 2289行 2299行
--> ActivityStack --- resumeTopActivityUncheckedLocked 1501行
--> ActivityStack --- resumeTopActivityInnerLocked 1532行 1961行
--> ActivityStackSupervisor --- startSpecificActivity 1961行
这里是核心代码 是step 2 a 和 step 2 b的分支判断的地方
void startSpecificActivity(ActivityRecord r, boolean andResume, boolean checkConfig) {
// Is this activity's application already running?
final WindowProcessController wpc =
mService.getProcessController(r.processName, r.info.applicationInfo.uid);
boolean knownToBeDead = false;
if (wpc != null && wpc.hasThread()) {
//step 2 b 当前APP进程已经存在 直接启动对应Activity
try {
realStartActivityLocked(r, wpc, andResume, checkConfig);
return;
} catch (RemoteException e) {
Slog.w(TAG, "Exception when starting activity "
+ r.intent.getComponent().flattenToShortString(), e);
}
// If a dead object exception was thrown -- fall through to
// restart the application.
knownToBeDead = true;
}
r.notifyUnknownVisibilityLaunchedForKeyguardTransition();
final boolean isTop = andResume && r.isTopRunningActivity();
//step 2 a 当前APP进程不存在 调用 Zygote进程去fork APP进程
mService.startProcessAsync(r, knownToBeDead, isTop, isTop ? "top-activity" : "activity");
}
未完待续。。。
以上是关于Android 11(platfrom 30)APP启动流程(含Activity)核心点记录的主要内容,如果未能解决你的问题,请参考以下文章
来自带有 API 30 (android 11) 的三星物理模拟器的错误 Android 11 -> java.net.SocketTimeoutException