關于啟動流程,過程相對復雜,本文只寫最重要的一段代碼?其他代碼,讀者自己分析。
參考文章:Activity啟動流程
ActivityStackSupervisor.java
方法名:startSpecificActivityLocked
void startSpecificActivityLocked(ActivityRecord r,
? ? ? ? boolean andResume, boolean checkConfig) {
// Is this activity's application already running?
? ? ProcessRecord app =mService.getProcessRecordLocked(r.processName,
? ? ? ? ? ? r.info.applicationInfo.uid, true);
? ? r.getStack().setLaunchTime(r);
//如果參在該進程,
? ? if (app !=null && app.thread !=null) {
try {
if ((r.info.flags&ActivityInfo.FLAG_MULTIPROCESS) ==0
? ? ? ? ? ? ? ? ? ? || !"android".equals(r.info.packageName)) {
// Don't add this if it is a platform component that is marked
// to run in multiple processes, because this is actually
// part of the framework so doesn't make sense to track as a
// separate apk in the process.
? ? ? ? ? ? ? ? app.addPackage(r.info.packageName, r.info.applicationInfo.versionCode,
? ? ? ? ? ? ? ? ? ? ? ? mService.mProcessStats);
? ? ? ? ? ? }
realStartActivityLocked(r, app, 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.
? ? }
//不存在該進程,就創建一個進程。
mService.startProcessLocked(r.processName, r.info.applicationInfo, true, 0,
? ? ? ? ? ? "activity", r.intent.getComponent(), false, false, true);
}