阅读前请先阅读上篇 Android体系揭秘(一)-Activity建议流程(上)

Android 10

央求ATMS

Android 10开发不再是直接央求AMS,而是央求ActivityTaskManagerService。流程与央求AMS相似

Android体系揭秘(一)-Activity发动流程(下)

前面与Android 8相同,也是先走
Activity.startActivity() -> Activity.startActivityForResult() -> Instrumentati线程池面试题on.execStartActivity
的流程

只是execStartActivity里面不是不是经过ActivityManager而是Acti安全期是哪几天vityTaskManage安全出产法r获取Service
frameworks/base/cor安全出产法e/java/android/a枸杞pp/Instrumentation.java

puappearblic Activ安全教育日是哪一天ityResult execStartActivity(
Context who, IBinder contextThread, IBinder token, Activity target,
Inten宫崎骏t intent, int requestCode, B安全出产法undle options) {APP
IApplicationThread whoThread = (IApplicationThread) contextThread;
...
try {
...
int result = ActivityTaskManager.getService().startActivity(whoThread,
who.getBasePackageName(), who.getAttributionTag(), intent,
intent.resolveTypeIfNeeded(who.getContentResolver()), token,
target != null ? target.mEmbeddedID : n宫崎骏ull, requ安全estCode, 0, null, options);
checkStartActivityRes安全教育日是哪一天ult(result, intent);
} catch (RemoteExceptio工商银行n e) {线程和进程的差异是什么
throw new RuntimeException("Failure from system"线程池的七个参数, e);
}
return null;
}

当然获取到的也不是IActivityM接口测验anager 而是 IActivityTaskManager

frameworks/base/core/java/android/app/ActivityTaskManager.java

@SystemService(Context.ACTIVITY_TASK_SERV公积金借款ICE)
public class ActivityTa线程是什么意思skManager {
public staticgoogle IActivityTaskManager getService() {
return宫崎骏 IActivityTaskManagerSingleton.get();
}
@Unsupported宫崎骏AppUsa线程是什么意思ge(trackingBug = 129726065)
private static final Sing接口协议leton<IAcapp装置下载tivityTaskManager> IActivityTaskManagerSingleton =
new Singleton&宫颈癌lt;IActivityTaskManager>() {
@Override
protected IActivityTaskManager create() {
final IBinder b = ServiceManager.getService(Context.A宫崎骏CTIVITY_TASK_SERVICE);
re线程的几种状况turn IActivityTaskManager.Stub.asInterface(b);
}
};
}

咱们看到AMS绑定的AIDL接口仍然是IActivityMana线程安全ger

frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java

public class ActivityManagerService ex接口测验tends IActivityManager.Stub
implements Watchdog.Moni安全教育渠道登录tor, BatteryStatsImpl.BatteryCallba接口测验面试题ck {

查找代码找到ActivityTaskManagerService绑定了IActivityTaskManager,应该是AMS把部分作业分配出去了。
frameworks/base/services/core/java/com/android/server/安全手抄报wm/Activ线程同步ityTaskManagerService.java

/**
* System线程池面试题 service for managing activities and their containers (安全出产法task, stacks, displ公积金ays,... ).
*
* {@hide}
*/
public class Ac安全教育渠道登录进口tivityTaskManagerService extends IActivityTaskManager.Stub {

ATMS发送指令到ActivityThread

Android体系揭秘(一)-Activity发动流程(下)

咱们继续看下ActivityTaskManagerService的startActivity方安全教育渠道登录进口

frameworks/base/services/core/java/com/android/公积金server/wm/ActiappearancevityTaskManagerService.java

    @Override
public final int st枸杞artActi线程池原理vity(IApplicationThread caller, String callingPackage,
Intent intent, String resolvedType, IBinder resultTo,
String resultWho, int requestCode, int startFlags, ProfilerInfo profilerInfo,
Bundl线程池的七个参数e bOptions) {
return startAc线程和进程的差异是什么tiviGotyAsUser(caller, call接口ingPackage, intent, resolvedType,
r接口crc过错计数esultTo, resultWho, requestCode, startFlags, profilerInfo, bOptions,
UserHandle.getCallingUserId());接口测验面试题
}

它调用了star安全tActivityAs安全出产法User办法

 @接口测验Override
public int startAct宫颈癌ivityAsUser(IApplicationThread caller, String callingPackage,
Intent intent, String resolvedType, IBinder resultTo,
String resultWho, int requestCode, int startFlags, ProfilerInfo profilerInfo,
Bund安全期是什么时分leappreciate bOptions, int userId) {
return startActivityAsUser(接口是什么caller, callingPackage, callingFeatu接口协议reId, in接口类型tent, resolvedType,
resultTo安全出产法, resultWho, requestCode, startFlags, profilerInfo, bOappointmentptions, userId,
true /*val线程撕裂者idateIncomingUser*线程的几种状况/);
}
private int startActivityAsUser(IApplicationThrea线程撕裂者d caller, Strin接口crc过错计数g callingPackage,
Intent intent, String resolvedType,狗狗币
IBinder resultTo, String resultWho, int requestCode,安全 int startFlags,
ProfilerInfo profilerInfo, Bundle bOptions, int userId, b龚俊oolean validateIncomingUser) {
asser安全期是什么时分tPackageMatchesCallingUi接口d(callingPackage);
enforceNotIsolaapproachtedCal安全手抄报ler("startActivityAsappointmentUser");
userId = getActivityStartController().checkTargetUser(userId, validateIncomingUser,
Binder.getCallingPid(), Binder.getCallingUid(), "startActivityAsGoUser");
// TOGoDO: Switch to user app stacks h公积金借款ere.
return getActivitySapproachtartController().obtai线程池的七个参数nStarter(int接口的效果ent, "startActivityAsUser")
.setCaller(caller)
.setCallingPackage(安全教育日是几月几日callingPackage)
.setResolvedType(resolved接口Type)
.接口setResultTo(resultTo)
.setResultWho(resultWho)
.setRequestCode(reque线程stCode)
.setStartFlags(startFlags)
.setP安全教育渠道登录进口rofilerInfo(profilerInfo)
.setActivityOptions(bOptions)
.setUserId(userId)
.execute();
}

getActivitySta接口卡rtController()回来的是一个ActivityStarterController政策

frameworks/base/services/core/java/com/android/server接口测验面试题/wm/ActivityStartController.java

    ActivityStarter obtainStarter(Intent intent, String reason) {
return mFactory.obtain().setIntent(intent).setReason(reasoapp装置下载n);
}

而o线程的几种状况btainStarter毕竟回来Activity接口的效果Starter

fra线程同步meworks/base/services/core/java/com/android/server/wm/ActivityStarter.java

int execute() {
try {
// TODO(b/6475安全期是哪几天0076): Look into passing request directly to t安全期是哪几天hese methods to allow
// for transactional diffs and prapproacheprocessing.
if (mRe龚俊quest.mayWait) {
return startActivitappstoreyMayWait(appearancemReq接口类型uest.caller, mRequest.callingUid,
mRequest.callingPackage, mRequest.realCallingPid, mRequest.线程撕裂者realCallingUid,
mR枸杞equest.intent, mRequest.resolvedType,
mRequest.voiceSession, mRequest.voiceInteractor, mRequest.resultTo,
mRequest.resultWho, mRequest.requestCode, mRequest.startFlags,
mRequest.profilerInfo, mRequest.waitResult, mRequest.glo接口协议balConfig,
m线程撕裂者Request.activityOp接口测验tions, mRequest.ignoreTarapplicationgetSecurgoogleity, mRequest.userId,
mRequest.inTask, mRequest.reason,
mRequest.allowPendingRemoteAnimationRegistryLookup,
mRequest.originatingPendingIntent, mRequest.allowBackg安全出产法roundActivityStart);
} else {
ret安全期是什么时分urn startActivity(mRequest.caller, mRequest.intent, mRequest.ephemeralIntent,
mRequest.resolvedType, mRequest.activityInfo, mR宫崎骏equest.resolveInfo,
mRequest.voiceSession, mRequest.voiceIntera接口和抽象类的差异ctor, mRequest.resultTo,
mRequest接口测验.resultWho, mRequest.requestCode, mRequest.callingPid,
mRequest.callingUid, mRequest.callingPackage, m宫颈癌Request.realCalli线程同步ngPid,
mRequest.realCallingUid, mReq安全手抄报uest接口和抽象类的差异.startFlags, mRequest.activityOptions,
mRequest.ignoreTargetSec安全教育日是几月几日urity, mRequest线程池.componentSpecified,
mRequest.outActivity, mRequest.inTask, mRequest.reason,
mRequest.allowPendingRemoteAnimationR线程的几种状况egistryLookup,
mRequest.originatingPendingI安全ntent, mRequest.allowBackgroundActivityStart);
}
} finally {
onExecutionComplete();
}
}

安全期计算器儿有两种建议办法,咱们挑选其间一种接着看下去


private i安全教育渠道nt startActivityMayWait(IApplicatio安全期是什么时分nThread caller, int callingUid,
String callingPackage, int requestRealCallingPid, int requ宫颈癌estRealCallingUid,
Inteappointmentnt intent, String resolvedT接口的效果ype, IVoiceInteractionSession voice枸杞Session,
IVoiceInteractor voiceInteractor, IBinder r线程的几种状况esultTo, String resultWho,apple int requestCode,
int startFlags工商银行, ProfilerAPPInfo profilerInf线程的几种状况o, WaitResult ou线程池tResult,
Conapproachfigu线程同步ration globalConfig, SafeActivityOptions options, boolean ignoreTargetSecurity,
int userId, TaskRecord inTask, String reason,
boolean allowPen接口和抽象类的差异diapplicationngRemoteAnimationRegistryLookup,
PendingIntentRecordgoogle originatingPendingIntent, b线程的几种状况oolean allowBackg线程池面试题roundActivityStart) {
...
int res = star线程池tActivity(caller, intent, ephemeralIntent, resolvedType, aInfo, rInfoappear,
voiceSessio接口协议n, voiceInt接口crc过错计数eractor, resultTo, resultWho, requestCode, calli线程池ngPid,
calliapproachngUid, callingPackage, realCallingPid, r线程安全ea线程是什么意思lCalli安全ngUid, startFlags, options,
ig线程池noreTargetSecurity, comp宫崎骏on接口测验面试题entSpecifi线程池的七个参数ed, outRecord, inTask, reason,
allowPendingRemoteAnimationRegistryLookup, originatingPendingIntent,
allowBackgroundActivityStart);
...
}

startActivityMayWait是安全建议,毕竟仍是调用startActivity办法

    private int startActivity(IApplicationThread caller, Intent intent, Intent ephemer安全手抄报alIntent,
IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor,
IapproveBinder resultTo, String resultWho, int requestCode, int callingPid, int callingUid,
String callingPackage, int realCallingPid, int realCallingUid, int startFlags,
SafeActivityOptions options, boappointmentolean ignoreTargetSecurity, boolean componentSpecifie接口crc过错计数d,
ActivityRecord[] outActi安全教育渠道登录进口vity, TaskRecord inTask, String reason,
boolean allowPendingRemoteAnimationRegistryLookup,
P宫颈癌endingIntentR接口协议ecord originatingPendingIntent, boolean allowBackground宫颈癌ActivityStart) {
.....
mLastStartActivityResult = startActivity(caller,appreciate intent, epheme安全出产法ralIntent, resolvedType,
aInfo, rInfo, voiceSession, voiceInteractor, resultTo, resultWho, requestCode,
callingPid, callingUid, callingPackage, realCallingPid, realCallingU龚俊id, startFla接口测验的流程和过程g安全教育日是几月几日s,
options, ignoreTargeapproachtSecuri线程安全ty, componappstoreentSpecified, mLastStartActivityRecord,
inTask, allowPendingRemoteAnimationappreciateRegistryLookup, originatingPendin接口和抽象类的差异gInapp装置下载tent,
alappearancelowBackgroundActivitySta接口rt);接口测验面试题
...
retu接口crc过错计数rn getExt安全教育渠道登录进口ernalResult(mLastStartActivityResult);
}
private int startActivity(finalapp装置下载 ActivityRecord r, Activit线程是什么意思yRecord sourceRecord,
IVoiceInteractionS线程同步ession voiceSe接口卡ssion, I接口卡VoiceInteractor voiceInteractor,安全教育渠道登录
int线程池的七个参数 startFlags, b公积金oolean doResume, A线程池原理ctivityOptions options, TaskRecord inTask,
ActivityRecord[] outActivity, boolean restrictedBgActivapproachity) {
.APP..安全教育渠道登录进口
try线程池原理 {宫崎骏
...Go
result = startActivityUnchecked(r, sourceRecord, voi接口crc过错计数ceSession, voiceInteractor,
startFlags, doResume, options, inTask, ou线程tActivity, restrictedBgActivity);
}
...
}

看下startActivityUnchecked办法


pappearrivate int startActivityUnchecked(final ActivityRecord r, ActivityRecord sourceRecord,
IVoiceInterac安全教育日是哪一天tionSess线程池的七个参数ion voice接口卡Session, IVoiceInteractor voiceInteractor,
int startFlags, boolean doResume, ActivityOptions options, TaskRecord inTask,appearance
Ac接口crc过错计数tivityRecord[] outActivity, boolean restri安全教育渠道登录ctedBgActivity) {
...
mTargetStack.startAcapproachtivityLocked(mStartActivity, topFocused, newTask, mKeepCurTransition,
mOptions);
if (mDoResume) {
final ActivityRecord topTaskActivity =
mStartActivity.get线程和进程的差异是什么TaskRecord().topRunningActivityLocked接口测验();
...
mRootActivityCon宫崎骏tainer.resumeFocusedappearStacksTopActivities(
mTargetStack,线程和进程的差异是什么 mStartActivity, mOptions);
}
}
..线程池.
return START_SUCCESS;
}

这儿调用了RootActivityCont线程的几种状况ainer的resumeFocusedStacksTopActiviti线程es办法

frameworks/base/ser安全手抄报vices/core/java/com/android/serve接口卡r/wm/RootActivityContainer.java


boolean resumeFocusedStacksTopActivities() {
return resumeFocusedStacksTopActivities(nullapplication, null, null);
}
boolean resumeFocusapproveedStacksTopActivities(
ActivityStack targetStack, ActivityRecordapple target,公积金 ActivityOptions targetOptions) {
...
for (int display狗狗币Ndx = getChildCount() - 1; displ枸杞ayNdx >= 0; --displ宫颈癌疫苗ayNdx) {
...
if (!resapproveumedOnDisplay) {
final Activity安全手抄报Stack focusedStack = display.getFocusedStack();
if (focusedStack != null) {
focusedStack.resumeTopActi公积金vityUncheckedLocked(target, targetOptions);
}
}
}
return r线程是什么意思es线程池的七个参数ult;
}

接下来又走到了ActivityStack

frameworks/base/services/core/java/com安全/android/server/wm/ActivityStack接口.java

   boolean resumeTopActivityUncheckedLocked(ActivityRecord prev, ActivityOptions options) {
...
result = resumeTopActivi安全期是什么时分tyInnerLocked(prev, options);
....
}
private boolean resumeT接口的效果opActivityInnerLocked(ActivityRecord prev, A线程池ctivityOptions options) {
....
mStackSupervisor.startSpecificActivityLocked(ne接口测验xt, true, false);
...
}

resume线程撕裂者TopActi线程安全vityInnerLocked跳转到ActivityStackSupervisor进行下一步

frameworks/base/services/core/java/com/android/server/wm/A线程的几种状况ctivityStackSupervisor.java

   void startSpecificActivityLocked(ActivityRecord r, boolean andResume, boolean checkConfig) {
// 先判别运用是否建议
final WindowProcessCapproachontroller wpc =
mServappleicgooglee.getP工商银行rocessController(r.processName, r.in公积金借款fo.applicationInfo.uid);
boolean knownToBeDead = false;
if (wpc != null && wpc.hasThread()) {
try {
// 运用已建议则发龚俊起Activity
realStartActivityLocked(r, wpc, andResume, checkConfig安全教育日是哪一天);
return;
} catch (RemoteException e) {
Slog.w(TAG, "Exceappreciateption when start线程同步ing activity "
+ r.intent.getComponent().flattenToShortString(), e);
}
// If a dead object exception was thrown -- fall through to
// restart the application.
knownToBeDead = true;
}
...
try {
...
/approve/ 奉告建议运用
final Message msg = PooledLambda.obt线程池ainMessage(
ActivityM安全教育渠道anagerInternal接口::startProcess, m枸杞Service.mAmInternal, r.procesappstoresName,
r.info.applicatio安全教育渠道登录进口nInfo, knownToBeDead接口crc过错计数, "activi安全tappeary", r.intent.getComponent());
mService.mH.sendMessage(msg);
} finally {
Trace.tracappleeEnd安全出产法(TRACE_TAG_ACTIVITY_MANAGER);
}
}

这儿会判别是否第一个Activity,若不是直接建议Activity,否则奉告ATMS建议运用。这一节咱们只剖析直接建议Activity的状况

boolean realStartActivityLocked(Act线程是什么意思ivityRecord r, WindowProcessController proc,安全教育渠道
boolean a接口测验面试题ndResume, boolean checkConfig) throws Remapp装置下载oteException {
...
// Create activity launch transaction.
final ClientTransactiappointmenton clientTransaction = CGolientTransaction.obtain(
proc.getThread(), r.appToken);
final DisplayContent dc = r.getDispla宫颈癌疫苗y().mDisplayContent;
// 这儿的La接口测验unchActivityItem要特别注意,后边会用到
clientTransaction.addCallback(LaunchActGoivityItem.obtain(new Intent(r.intent),
System.identityHashCode(r), r.info,
// TODO: Have this take the merged configu线程池的七个参数ration instead of separate glo线程池原理bal
// and override configs.
mergedConfiguration.getGlobalCogooglenfiguration(),
mergedConfiguration.getOverrideConfiguration(), r.compat,
r.线程和进程的差异是什么launchedFromPackage, task龚俊.voiceInteractor, proc.getRep线程池原理ortedProcState(),
r.icicle, r.persistentState, resu线程撕裂者lts, newIntents,
dc.isNextTransitionForward()Go, proc.createProfilerInfoIfNeeded(),
r.assistToken));
// Set desired final state.
final ActivityLifecycleItem lifecycGoleItem;
if (andResume) {
lifec狗狗币ycleItem = ResumeActivityItem.obtain(dc.isNextTransitionForward());
} else {
lifecycleItem = PauseActivityItem.obtain();
}
clientTransaction.setLifecycleStateRequest(lifecycleItem);
// 经过Lifecycle奉告建议
mService.getLifecycleManager().scheduleTransaction(clientTransaction);
...
return true;线程池面试题
}

注意下这儿的LaunchActivityItem,这个会作为lifecycleItem发给ActivityThread,后边又用到

fr安全手抄报am线程是什么意思eworks/base/services/core/java/com/android/server/wm/ActivityTaskManagerService.java

ClientLifecycleManager getLifecycleManager() {
return mLifecycleManager;
}

接下来经过Lifecycle奉告建议Activity,其接口是什么间mService为ActivityTaskManagerService,

ActivityTapprovehread接口卡建议新的Activity

Android体系揭秘(一)-Activity发动流程(下)
如图所示,ClientLifecycleManager会调用IApplicationThread的scheduleTransaction办法
frameworks/base/services/core/java/com/andr安全教育渠道登录oid/server安全期是哪几天/w接口crc过错计数m/ClientLifecycleManager.java

vo安全期是什么时分id scheduleTransaction(CapplicationlientTransaction transaction) throws RemoteException {
final IApplicationThread client = transaction.getClient(线程池);
transacti安全on.schedule();
if (!(client instanceof Binder)) {
// If client is not an instance of Binder - it's a remote call an宫崎骏d at this point it is
// safe to recycle线程池原理 tappearancehe object. A狗狗币ll objects used for local calls will be rapproachecycled after
// the transaction is executed on client in ActivityThread.
transaction.recycle();
}
}

frame安全教育日是哪一天works/base/core/java/android/app/servertransaction/ClientTransaction.java


private IAp公积金plicationThread mClient;
public void schedule() throws RemoteException {线程池
mClient.scheduleTransacappletion(this);
}

而IApp接口测验licationThread的scheduleTrans公积金action办法调用了ActivityThread父类的scheduleTransaction办法
fram接口测验的流程和过程eworks/base/core/java/android/app/ActivityThread.java

pubapplelic final cGolass ActivityThread extends ClientTransactionHandler {
private class ApplicationThread extends IAp宫崎骏plicationThread.Stub {
@Ovappstoreerride
public void s安全期计算器cheduleTransaction(ClientTransaction transaction) throws RemoteException {
ActivityThread.this.scheduleTransacappleti接口和抽象类的差异on接口协议(transaction);
}
}
}

frameworks/base/core/java/android/app/ClientTransactionHandler.java

    void schedu宫颈癌leTransaapprovection(ClientTransaction transact安全出产法ion) {
transaction.preExecute(this);
sendMessage(ActivityThread.H.EXECUTE_TRANSACTION, transaction);
}

毕竟是向H发送包括EXECUTE_TRANSACTION和transaction的Messageappear

   private void sendMessage(int what,公积金 Object obj, int arg1, int arg2, bapp装置下载ooleaapplicationn async) {
if (DEBUG_MESSAGES) {
Slog.v(TAG,
"SCHEDULE " + what + " " + mH.codeToString(what) + "安全: " + arg1 + " / " + obj);接口
}
Message msg = Message.obtain();
msg.what = wh接口卡at;
msg.obj = obj;
msg.arg1 = arg1;
m公积金借款sg.arg2 = arg2;
if (asyncapproach) {
msg.se安全期计算器tAsynchronous(true);
}
mH.sendMessage(msg);
}
 class接口crc过错计数 H接口类型 extends Handler {
...
p接口卡ublic static final int EXECUTE_TRANSACTION = 159;
...
public void handleMessage(Message msg) {
if (DEBUG_MESSAGES) Slog.v(TAG, ">>> handling: " + codeToStri接口是什么ng(msg.线程池what));
switch (msg.what) {
...
case E接口是什么XECUTE_TRANSapproachACTION:
final ClientTransaction transaction = (C公积金lientTransaction) msg.obj;
mTransactionExecutor.execute(transaction);
if (isSystem()) {
// Client transactions inside system process are recycled on the client side
// instead of ClientLifecycleManager to avoid being cleared before this
// message is handled.
transaction.recycle();
}
// TODO(lifecycler): Recycle locally scappstoreheduled transactions.
break;
...
}

H收到msg之后实行transaction

fra公积金meworks/base/core/java/android宫崎骏/app/servertransaction/TransactionExecutor.java

public void execute(ClientTransaction transaction) {
if (DEBUG_RESOLVER) Slappleog.d(approachTAG, tId(transaction) + "Start resolving transaction")工商银行;
final IBinder token = transaction.getActivityToken();
if (token != null) {
final Map<IBinder, ClientTransactionItem> activitiesToBeDestroyed =
mTransactionHandler.getActivitiesToBeDestroyed();
final ClientTransacti接口的效果onItem destroyItem = activitiesToBeDestroyed.get(token);
if (destroyItem != null) {
if (applicationtransaction.getLifecycleStateRequest() == destroyItem) {
// It is going to execute the transaction that will destroy activity with the
// token, so the corres安全出产法ponding to-be-destroyed record can be removed.
activitiesToBeDestroyed.r接口协议emove(token);
}
if (mT线程同步ransactionHandler.getActivityClient(token) == null) {
// The activity has not be接口类型en created but has been re接口测验面试题quested to destroy, so all
// transactions for the token are just like being can安全出产法celled.
Slog.w(TAG, tId(transaction) + "Skip pre-destroyed trans接口测验面试题actapplicationion:n"
+ transactionTo狗狗币String(transaction, mTransactionHandler));
retur枸杞n;
}
}
}
if (DEBUG_RESOLVER) Slog.d(TAG, transa线程同步ctionToString(transa线程池原理ction, mTransactionH线程池原理and接口ler));
executeCallbac接口测验ks(transaction);
executeLifecycleState(transaction);
mPendingActions.clear();
if (DEBUG_RESOLVER) Slog.d(TAG, tId(transaction) + "End resolving transaction");
}

这儿咱们重视execu线程池的七个参数teLifecycleState办法

  /** Transition to the final state if reapproachquest线程池的七个参数ed by the transaction. */
privatapplee void executeLifecycleState(ClientTransaction transaction) {
final Activit线程池yLifecycleItem lifecycleItem = transaction安全教育渠道登录.getLifecycleStateRequest();
if (lifecycleItem == null) {安全
// No life线程安全cycle request, return early.
return;
}
final IBinder token安全出产法 = transaction.getActivityToken();
final ActivityClientRecord r = mTranappreciatesactionHandler.getActivityClient(token);
if (DEBUG_RESOLVER) {
S安全log.d(TAG, tId(transaction) + "Resolving lifecycle state: "
+ lifecycleItem + " for activiappreciatety: "
+ getShortActivityName(token, mTransactionHandler));
}
if (r == null) {
// Ignore requests安全期是哪几天 for non-existent client records for now.
return;
}
// Cycle t安全教育日是几月几日o the state right before the final requested stat宫颈癌e.
cycl接口和抽象类的差异eToPath(r, lifec线程同步ycleItem.getTargetState(), true /* excludeLastState */, transaction安全期计算器);
// Execute安全教育日是哪一天 the final transi接口协议tion with proper parameters.
lifecycleItem.execute(mTra接口是什么ns狗狗币actionHandler, token, mPendingActions);
lifecycleItem.postExecute(mTransactionHandler,安全教育渠道 token, mPendingActions);
}

这儿的life线程池原理cycleItem 便是上节说到的LaunchActiv接口测验面试题ityItem,咱们看下它的完成

frameworks/base/core/java/android/app/servertransaction/LaunchActivityItem.java

  @Override
public void execute(ClientTransactionHandler client, IBinder token,
PendingTransactio线程池的七个参数n安全手抄报Actions pend接口是什么ingActions) {
T接口是什么race.trac线程池面试题eBegin(TRACE_TAG_ACappearanceTIVITY_MANAGER, "activityStart");
ActivityCli接口entRecord r = new Activit安全期是什么时分yClientRecord(token, mIntent, mIdent, mInfo,
mOverrideC安全教育渠道登录onfig, mC线程和进程的差异是什么ompatInfo, mReferrer, mVoiceInteractor, mState, mPersistentSta线程安全te,
mPendingRegooglesults, mPendingNewIntents, mIsForward,
mProfilerInfo, client, mAssistToken);
client.handleLaunchActi狗狗币vity(r, pendingActions, null /* customIntent */);
Trace.approvetraceEnd(TRACE_TAG_ACTIVITY_MANAGER);
}

client其实便是Activit接口协议yThread,接下来便是调用ActivityThread线程同步的handle接口和抽象类的差异LaunchActivity办法,后边的流程与Android基安全教育日是哪一天本一起,就不再赘述了

Android 11

Android 11与Android 10的进程改变不大,只带着时序图说下不同之线程的几种状况

央求ATMS

Android体系揭秘(一)-Activity发动流程(下)

这一步基本一起,只是Android 11startActi宫崎骏vity办法多了一个callingFeatureId参数,后续也会传给ActivityStarter

fr安全期是什么时分ameworks/base/services/core/线程java/com/android/server/app装置下载wm/ActivityTas线程安全kManagerService.java

    @Override
pub工商银行lic final in接口crc过错计数t starapplicationtActivity(IApplicationThread caller, String callingPackage,
Intent int狗狗币en线程和进程的差异是什么t, String resolved公积金Type, IBinder resultTo宫颈癌疫苗,
String resultWho, int requestCode, int startFlags, ProfilerInfo profilerInfo,
Bundle bOptions) {
return star公积金借款tActivityAsUser(caller, calli公积金n接口和抽象类的差异gPackage, intent, resolvedType,
resultTo, resultWho, requestCode, startFlags, profilerInfo, bOptions,
UserHa接口协议ndle.getCallingUserI接口d公积金())接口crc过错计数;
}

ATMS发送指令到ActivityThread

Android体系揭秘(一)-Activity发动流程(下)

要点看下时序图里面赤色的部分:

  • ActivityStarter逻辑有些改动
  • RootActivityContainer改成了RootWiapplicationndowContainer
  • ActivityStackSupe龚俊rvisor->startSpecificActivityLock改为startSpecificActivity

然后看下这部分的代码
frameworks/base/services/core枸杞/java/co线程是什么意思m/android/server/wm/ActivityStarter.java

int execute() {
try {
...
int res;线程撕裂者
s宫颈癌ynchronized (mService.mGlobalLock) {
...
res = ex安全出产法ecut安全教育渠道登录进口eRequest(mRequest);
...
mSupervisor.getActivityMetricsLogger().appearnotifyActivityLaunched(launchingState, res接口测验,
mLastStartActivityRecord);
return getExternalResult(mRequest.waitResult == null ? res
: waitappstoreForResult(res, mLastStartActivityRecord));
}
} finally {
onExecutionComplete();
}
}

executeRequest的代码贼多贼多,但咱们在里面找到了一个了解的办法名startAc线程池面试题tivityUnchecked

  private int executeReque公积金st(Request request) {
...
int err = ActiappstorevityManager.START_SUCCESS;
...
mLastStartActivityResult = startActivityUnchecked(r, sourceRecord, voiceSession,
request.voiceInteractor, startFlags, true /* doResume */, checkedOptions, inTask,
restrictedBgActivity, intentGrants);
if (request.outActivity != null) {
rappreciateequest.outAct宫颈癌ivity[0] = mLastStartActivityRecappearanceord;
}
return mLastStartActivityRe线程和进程的差异是什么sult;
}

当然,它也变了

    private int startActivityUnchecked(final ActivityRecord r, ActivityRecord sourceRecord,
IVoiceInteractionSession voiceSession, IVoiceInteractor voice工商银行Interactor,
int startFlags接口测验的流程和过程, boolean doResume, ActivityOptions options, Task inTask,
boolean restrictedBgActivity, NeededUriGrants inte安全期计算器ntGrants) {
int result = START_CANCELED;
final ActivityStack startedActivityStack;
try {
mService.deferWindowLayout();
Trace.traceBegin(Trace.接口TRACE_TAG_WINDOGoW_MANAGER, "startActivityInner");
result = startActivityInner(r, sourceRecord, voiceSession, voiceInteractor,
startFlags, doResume, options, inTask, restrictedBgActivity, intentGrants);
} final安全ly {
Trace.trace线程和进程的差异是什么End(Trace.TRACE_TAG_WINDOW_MANAGER);
startedActivityStack = handle接口是什么StartResult(r, resul宫颈癌t);
mService.continu线程安全eWindowLay接口协议o线程池原理ut();
}
postStartAc宫颈癌tivityProcessing(r, result, startedA线程同步ctivityStack);
return result;
}

int start线程和进程的差异是什么ActivityInner(final ActivityRecord r, ActivityRapplicatione安全出产法cord sappearourceRecord,
IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor,
int staapplertFlags, boolean doResume, ActivityOptions options, Task inTask,
boolean restrict安全教育渠道edBgActivity, NeededUriGrants intentGrants) {
..安全手抄报.
if (mTargetStack == null) {
mTargetStack = getLaunchStack(mStartActivity, mLaunchFlags, targetTask, mOptions);
}
...
mTa接口测验面试题rgetStack.startActivityL接口卡ocked(mStartActivity, topStack.getTopNonFinishingActivity(),
newTa龚俊sk, mKeepCurTransition狗狗币, mOptions);
if (mDoResume) {
...
mRootWindowContainer.resumeFocusedStacksTopActivities(
mTargetStack,apple mStartActivity, mOptions);
...
}
}
...
return START_SUCCESS;
}

这儿调用了RootWindowContainer的resumeFocusedStacksTopActivities办法

frameworks/base/services/core/java/com/android/server/wmappearance/RootWindowContainer.java


boolean resumeFocusedStacksTopActivapp装置下载ities() {
return resumeF线程池原理ocusedS接口测验tacksTopActivities(null, null, null);
}
boolean resumeFocuse线程池面试题dStacksTopActivities(
ActivitySta安全出产法ck targetStacGok, ActivityRecord target, ActivityOptions targetOptions) {
.安全..
for (int displayNdx = getChildCount() - 1; display安全教育渠道登录进口Ndx >= 0; --displayNdx) {
...
if (!re龚俊sume宫崎骏dOnDisplay) {
final ActivityStack focuse安全dStack = display线程池.getFocusedStack();
if (focusedStack != null) {
focusedStack.resum线程和进程的差异是什么eTopappreciateActivityUncheckedLocked(target, targetOptions);
}
}
}
return result;
}

接下来又走到了ActivityStack

frameworks/base/service线程池面试题s/core/java/com/androapproachidappstore/server/wm/ActivityStack.java

   boolean resumeTopActivityUncheckedLocked(ActivityRecord prev, ActivityO线程池ptions options) {
...
result = resumeTopActiappreciatevityInnerLocked(prev, options);
....
}
private boolean resumeTopActivityInnerLocked(ActivityRecord prev, ActivityOptions options) {
....
mStackSupervisor.startSpecificActi公积金vity(nextappearance, tru安全教育渠道e, false);
...
}

android 10为startSpecificActivityLock,11 为startSpecificActivity

frameworks/base/services/core/java/c接口测验om/androi宫颈癌d/server/wm/ActivityStackSupervisor公积金.java

   void startSpecificActivity(ActivityRecord r, boolean andResu接口crc过错计数me, boolean checkConfig) {
// 先判别运用是否发接口测验的流程和过程起
final WindowProcessController wpc =
mService.getProcessController(r.processName, r.info.application接口类型Info.uid);
boolean knownToBeDead = false;
if (wpc != null && wpc.hasThread()) {
try {
// 运用已建议则建议Activity
re线程撕裂者alStartActivityLocked(r,安全期是哪几天 wpc, andResume, checkConfig);
return;
} catch (RemoteException e) {
Slog.w(TAG, "Excepti线程池面试题on when安全教育渠道登录 starting activity "
+ r.安全期是哪几天intent.getComponent().flattengoogleToShortString(), e)安全教育渠道登录;
}
// If a dead object exception was th宫崎骏rown -- fall through to
// restart t安全教育日是几月几日he application.
knownToBeDead = true;
}
...
try {
...
// 奉告建议运用
final Message msg = PooledLambda.安全obtainMessage(
ActiAPPvityManagerInternal::startProcess, mService.mAmInt安全期计算器ernal, r.processName,
r.info.applicationInfo, kn接口和抽象类的差异ownToBeDead,线程和进程的差异是什么 "activity", r.intent.getComponent());
mService.mH.sendMessage(msg);
} finally {
Trace.traceEnd(TRACE_TAG_ACTIVITYapproach_MANAGER);
}
}

ActivityThread建议新的Activity

Android体系揭秘(一)-Activity发动流程(下)
这一进程流程没有改变

总结

Android 8 – 9

  • 调用startActivity后经过Instrumentation奉告AMS
  • AMS奉告ActivityStarter建议Activity
  • ActivityStarter奉告ActivityStack安全期是什么时分Supervisor线程同步,ActivityStackSuperviso线程和进程的差异是什么r协同ActivityStack处理一些库房业务,然后接口的效果奉告AppgooglelicationThread建议Activity
  • ApplicationThread奉告ActivityTh安全教育日是几月几日read发送建议音讯,ActiapproachvityThread向mH发送LAUNCH_ACTIVITY音讯
  • mH收到LAUNCH_ACTIVITY音讯后,经过主线程调用performLaunchAc安全教育渠道登录tivity办法创立Activity
  • 创立完后经过Instrumentation奉告Activity,然后Activity回调onCreate办法,奉告开发者Activity已创立

央求AMS

Android体系揭秘(一)-Activity发动流程(下)

AMS到ApplicationThread的调用进程

Android体系揭秘(一)-Activity发动流程(下)

Activity线程Thre线程池ad 建议Activity 的进程

Android体系揭秘(一)-Activity发动流程(下)

Android 10 – 11

  • 调用startActivity后经过线程Instrumenta接口tion奉告AMS的小弟ATMS
  • ATMS经过ActiviGotyStartController奉告ActivityStarter建议Activity公积金借款
  • ActivappleityStarter奉告RootActivityContaine安全教育渠道登录进口r(Android 11为RootWindowContainer),RootActivit安全出产法yContainer奉告ActivityStack处理库房
  • 运用ActivityStackSupervisor奉告Clie接口是什么ntLifecycleManager,并完全LaunchActivityItem政策
  • Cl接口和抽象类的差异ientLifecycleManager奉告ApplicationThread
  • ApplicationThread奉告ActivityThread发送建议音讯,ActivityThread向mH发送EXECUTE_TRANSACTI接口测验面试题ON音讯和LaunchActivityItem政策
  • mH收到EXECUTE_TRANSACTION音讯后,经过主线程实行LaunchActivityItem的execGoute办法,然后调用performLaunchActivity办法创立Activ接口测验面试题ity
  • 创立完后经过Instrumentation奉告Activity,然后Activity回调onCreate办法,奉告开发者Activity已创立

央求ATMS

Android体系揭秘(一)-Activity发动流程(下)

ATMS发送指令到Act公积金ivit线程和进程的差异是什么yThread

Android 10

Android体系揭秘(一)-Activity发动流程(下)

Android 11

Android体系揭秘(一)-Activity发动流程(下)
两个版本比照:

  • ActivityStarter逻辑有些改动
  • RootActivityContainer龚俊改成了RootWindowContainer
  • ActivityStackSupervisor->startSpecificActivityLock改为startSpecificActivity

Activit线程的几种状况yThr工商银行ead建议新的Activity

Android体系揭秘(一)-Activity发动流程(下)