Activity启动流程(七)再次回到本地并执行handleLaunchActivity
发布日期:2021-07-23 22:22:30
浏览次数:2
分类:技术文章
本文共 5841 字,大约阅读时间需要 19 分钟。
上文再次调用了
一:再次回到本地
mClient.scheduleTransaction(this);
这里和之前的逻辑一样,只是这次这里
public void execute(ClientTransaction transaction) { final IBinder token = transaction.getActivityToken(); log("Start resolving transaction for client: " + mTransactionHandler + ", token: " + token); executeCallbacks(transaction); executeLifecycleState(transaction); mPendingActions.clear(); log("End resolving transaction"); }
这次callBack里有东西了
看下executeCallbacks方法
/** Cycle through all states requested by callbacks and execute them at proper times. */ @VisibleForTesting public void executeCallbacks(ClientTransaction transaction) { final Listcallbacks = transaction.getCallbacks(); if (callbacks == null) { // No callbacks to execute, return early. return; } log("Resolving callbacks"); final IBinder token = transaction.getActivityToken(); ActivityClientRecord r = mTransactionHandler.getActivityClient(token); // In case when post-execution state of the last callback matches the final state requested // for the activity in this transaction, we won't do the last transition here and do it when // moving to final state instead (because it may contain additional parameters from server). final ActivityLifecycleItem finalStateRequest = transaction.getLifecycleStateRequest(); final int finalState = finalStateRequest != null ? finalStateRequest.getTargetState() : UNDEFINED; // Index of the last callback that requests some post-execution state. final int lastCallbackRequestingState = lastCallbackRequestingState(transaction); final int size = callbacks.size(); for (int i = 0; i < size; ++i) { final ClientTransactionItem item = callbacks.get(i); log("Resolving callback: " + item); final int postExecutionState = item.getPostExecutionState(); final int closestPreExecutionState = mHelper.getClosestPreExecutionState(r, item.getPostExecutionState()); if (closestPreExecutionState != UNDEFINED) { cycleToPath(r, closestPreExecutionState); } item.execute(mTransactionHandler, token, mPendingActions); item.postExecute(mTransactionHandler, token, mPendingActions); if (r == null) { // Launch activity request will create an activity record. r = mTransactionHandler.getActivityClient(token); } if (postExecutionState != UNDEFINED && r != null) { // Skip the very last transition and perform it by explicit state request instead. final boolean shouldExcludeLastTransition = i == lastCallbackRequestingState && finalState == postExecutionState; cycleToPath(r, postExecutionState, shouldExcludeLastTransition); } } }
我们在前面知道这里放了一个 LaunchActivityItem 所以
二 LaunchActivityItem类
看下LauncherActivityItem类的execute方法
@Override public void execute(ClientTransactionHandler client, IBinder token, PendingTransactionActions pendingActions) { Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityStart"); ActivityClientRecord r = new ActivityClientRecord(token, mIntent, mIdent, mInfo, mOverrideConfig, mCompatInfo, mReferrer, mVoiceInteractor, mState, mPersistentState, mPendingResults, mPendingNewIntents, mIsForward, mProfilerInfo, client); client.handleLaunchActivity(r, pendingActions, null /* customIntent */); Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); }
在这里终于handleLaunchActivity 了,注意,这里的ClientTransactionHandler其实是ActivityThread
三 handleLauncherActivity
看下handleLauncherActivity方法
/** * Extended implementation of activity launch. Used when server requests a launch or relaunch. */ @Override public Activity handleLaunchActivity(ActivityClientRecord r, PendingTransactionActions pendingActions, Intent customIntent) { // If we are getting ready to gc after going to the background, well // we are back active so skip it. unscheduleGcIdler(); mSomeActivitiesChanged = true; if (r.profilerInfo != null) { mProfiler.setProfiler(r.profilerInfo); mProfiler.startProfiling(); } // Make sure we are running with the most recent config. handleConfigurationChanged(null, null); if (localLOGV) Slog.v( TAG, "Handling launch of " + r); // Initialize before creating the activity if (!ThreadedRenderer.sRendererDisabled) { GraphicsEnvironment.earlyInitEGL(); } WindowManagerGlobal.initialize(); final Activity a = performLaunchActivity(r, customIntent); if (a != null) { r.createdConfig = new Configuration(mConfiguration); reportSizeConfigurations(r); if (!r.activity.mFinished && pendingActions != null) { pendingActions.setOldState(r.state); pendingActions.setRestoreInstanceState(true); pendingActions.setCallOnPostCreate(true); } } else { // If there was an error, for any reason, tell the activity manager to stop us. try { ActivityManager.getService() .finishActivity(r.token, Activity.RESULT_CANCELED, null, Activity.DONT_FINISH_TASK_WITH_ACTIVITY); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } } return a; }
这里有个注意点:在api27及之前,调用的是scheduleLaunchActivity 到28之后,这个方法找不到了,
换成了handleLaunchActivity
handleLaunchActivity可以说是activity启动的本地操作真正的入口了,下文将会以这个方法为起点继续探索activity启动过程
转载地址:https://blog.csdn.net/perfectnihil/article/details/91047742 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
逛到本站,mark一下
[***.202.152.39]2024年04月07日 10时35分28秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
XStream xml与javabean之间的互转
2019-04-27
Android应用构建:10:使用sdkmanager管理sdk
2019-04-27
Kubernetes基础:MacOS上设定Dashboard
2019-04-27
#力扣 MySQL:183. 从不订购的客户 @FDDLC
2019-04-27
#力扣 MySQL196. 删除重复的电子邮箱 @FDDLC
2019-04-27
Seekbar 属性 记录
2019-04-27
textview设置独特字颜色和背景颜色
2019-04-27
背景+带边框(圆角)的textview怎么设置
2019-04-27
第二技能
2019-04-27
算法的设计
2021-06-30
WinCE内存管理
2021-06-30
实验: 显式装入DLL时, DLL接口操作封装类
2021-06-30
资源: 辅助工具
2021-06-30
GetLocalIp
2021-06-30
experiment: 锁操作
2021-06-30
调试记录
2021-06-30
资料: vs2005IDE操作
2021-06-30
整理: 关于程序员的漫画
2021-06-30
goto and lable
2021-06-30