基于Api 30
一:activity启动
1. activity.startActivity(Intent intent); ->startActivity(intent, null);
->startActivityForResult(intent, requestCode, null);->mInstrumentation.execStartActivity()
// ActivityTaskManagerService
->ActivityTaskManager.getService().startActivity();->startActivityAsUser()->startActivityAsUser()
->getActivityStartController().obtainStarter().execute()->mFactory.obtain().setIntent().setReason().
getActivityStartController() => ActivityStartController(DefaultFactory())
->ActivityStarter.execute()->executeRequest()->startActivityUnchecked()->startActivityInner()
->resumeTopActivityUncheckedLocked()
//Activity没有被添加到进程返回false
if (next.attachedToProcess()) {
} else {
mStackSupervisor.startSpecificActivity(next, true, true);
}
//没有被添加到进程中
->realStartActivityLocked()
->clientTransaction.addCallback(LaunchActivityItem.obtain(new Intent(r.intent)
->mService.getLifecycleManager().scheduleTransaction(clientTransaction)
->ApplicationThread.scheduleTransaction() -> sendMessage(ActivityThread.H.EXECUTE_TRANSACTION, transaction)
->mTransactionExecutor.execute(transaction);
->client.handleLaunchActivity()
->ActivityThread.handleLaunchActivity()->performLaunchActivity()
->mInstrumentation.newActivity()
->Activity activity = (Activity)clazz.newInstance()
if (application == null) {
application = new Application();
}
activity.attach()
->mRootWindowContainer.resumeFocusedStacksTopActivities()
////进程不存在
->2.startProcessAsync() ->ActivityManagerService.startProcess()->startProcessLocked->handleProcessStartedLocked
->ProcessList : mService.mHandler.sendMessageDelayed(msg, usingWrapper) PROC_START_TIMEOUT_MSG
->processStartTimedOutLocked(ProcessRecord)->
//app进程存在
->1.realStartActivityLocked()
//上一个activity的pause 和下一个activity的resume
->resumeTopActivityInnerLocked()->startPausingLocked()
//mAtmService ActivityTaskManagerService getLifecycleManager()=>ClientLifecycleManager
->mAtmService.getLifecycleManager().scheduleTransaction()
// transaction => ClientTransaction mClient =>ActivityThread.ApplicationThread
->transaction.schedule();->mClient.scheduleTransaction(this);
//ActivityThread extends ClientTransactionHandler
->ClientTransactionHandler.scheduleTransaction()
->sendMessage(ActivityThread.H.EXECUTE_TRANSACTION, transaction);
->mTransactionExecutor.execute(transaction);
->executeCallbacks()
->performLifecycleSequence()
mTransactionHandler.handleLaunchActivity()
mTransactionHandler.handleStartActivity
mTransactionHandler.handleResumeActivity
mTransactionHandler.handlePauseActivity
mTransactionHandler.handleStopActivity
mTransactionHandler.handleDestroyActivity
mTransactionHandler.performRestartActivity
->handleLaunchActivity()->performLaunchActivity()
->mInstrumentation.newActivity(cl, component.getClassName(), r.intent)
->mInstrumentation.callActivityOnCreate()
->activity.performCreate(icicle, persistentState);
->performCreate()->onCreate()
网友评论