Activity.startActivity(intent)
Instrumentation.execStartActivity(this, IApplicationThread, IApplicationToken, this, intent, requestCode, options)
ActivityManagerNative.getDefault().startActivity
ActivityManagerService.startActivity
ActivityManagerService.startActivityLocked (建立新的ActivityRecord)
ActivityManagerService.startActivityUncheckedLocked
mActivityStackSupervisor.startActivityLocked
activityStack.startActivityLocked
mActivityStackSupervisor.resumeTopActivitiesLocked
activityStack.resumeTopActivityLocked
activityStack.resumeTopActivityInnerLocked
(首先呼叫原始Activity的startPausingLocked,即Activity.onStop)
mActivityStackSupervisor.startSpecificActivityLocked
1.如果程式已經啟動
mActivityStackSupervisor.realStartActivityLocked
ProcessRecord.thread.scheduleLaunchActivity
2.如果程式沒有啟動
ActivityManagerService.startProcessLocked
Process.start("android.app.ActivityThread", ...)
ActivityThread.main
new ActivityThread().attach(false)
ActivityManagerService.getDefault().attachApplication(IApplicationThread)
ActivityManagerService.getDefault().attachApplicationLocked
IApplicationThread.bindApplication
mH.sendMessage(H.BIND_APPLICATION, AppBindData)
ActivityThread.handleBindApplication(AppBindData)
ContextImpl appContext = ContextImpl.createAppContext
1. LoadedApk: data.info = getPackageInfoNoCheck(data.appInfo, data.compatInfo);
2. ContextImpl appContext = ContextImpl.createAppContext
3. new Instrumentation().init(instrContext, appContext, ...)
4. Application app = data.info.makeApplication
5. installContentProviders(app, providers);
6. mInstrumentation.callApplicationOnCreate(app);
mActivityStackSupervisor.attachApplicationLocked
mActivityStackSupervisor.realStartActivityLocked
app.thread.scheduleLaunchActivity
mH.sendMessage(H.LAUCH_ACTIVITY, new ActivityClientRecord)
-> ActivityThread.handleLaunchActivity
ActivityThread.performLaunchActivity
1.Activity activity = mInstrumentation.newActivity(cl, component, intent)
2.activity.attach(appContext, this, mInstrumentation, token, application, ...)
3.mInstrumentation.callActivityOnCreate(activity)
-> ActivityThread.handleResumeActivity
ActivityThread.performLaunchActivity
1.ActivityRecordClient.activity.performResume
Looper.myQueue().addIdleHandler(new Idler());
1.ActivityManagerNative.getDefault().activityIdle(a.IApplicationToken)
2.mActivityStackSupervisor.activityIdleInternalLocked
最後主要的是mActivityStackSupervisor中維護了一個mStoppingActivities隊
列,在Activity被pause的時候會新增到裡面,
3.stack.stopActivityLocked(r)
4.r.app.thread.scheduleStopActivity
以上已經完全分析了Activity的onPause、handleBindApplicationon、Create、onResume、onStop
-----------------------------------------------------------------------------------------------
Activity.finish
ActivityManagerNative.getDefault().finishActivity()
ActivityManagerService.finishActivity()
-----------------------------------------------------------------------------------------------