Android Activity启动流程

关于启动流程,过程相对复杂,本文只写最重要的一段代码?其他代码,读者自己分析。

参考文章: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);

}



你可能感兴趣的:(Android Activity启动流程)