startActivity流程
来源:互联网 发布:php 页面重定向方法 编辑:程序博客网 时间:2024/05/06 19:38
1. startActivity流程图
调用方Activity1通过调用startActivity()跳转到Activity2的流程图如下所示,后面将对其中重要步骤进行详细分析
2. startActivityMayWait()
startActivityMayWait()函数代码很长,其核心工作主要分为5个步骤:
1)确定目标Activity
2)获取目标Activity的信息
3)判断目标Activity所属进程是否是重量级的
4)调用startActivityLocked()执行启动操作
5)如果onResult不为空,需将结果写入变量中
final int startActivityMayWait(IApplicationThread caller, int callingUid, Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, int startFlags, String profileFile, ParcelFileDescriptor profileFd, WaitResult outResult, Configuration config, Bundle options, int userId){ // step1. 确定目标Activity if (intent != null && intent.hasFileDescriptors()) { throw new IllegalArgumentException("File descriptors passed in Intent"); } boolean componentSpecified = intent.getComponent() != null; // Don't modify the client's object! intent = new Intent(intent); // step2. 获取目标Activity的信息 ActivityInfo aInfo = resolveActivity(intent, resolvedType, startFlags, profileFile, profileFd, userId); synchronized (mService) { …… if (mMainStack && aInfo != null && (aInfo.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) { if (aInfo.processName.equals(aInfo.applicationInfo.packageName)) { if (mService.mHeavyWeightProcess != null && (mService.mHeavyWeightProcess.info.uid != aInfo.applicationInfo.uid || !mService.mHeavyWeightProcess.processName.equals(aInfo.processName))) { …… //step3.判断是否是重量级进程 if (mService.mHeavyWeightProcess.activities.size() > 0) { …… } …… } } //step4.调用startActivityLocked()执行启动工作</span> int res = startActivityLocked(caller, intent, resolvedType, aInfo, resultTo, resultWho, requestCode, callingPid, callingUid, startFlags, options, componentSpecified, null); //step5.outResult不为空时,将结果写入该变量中 if (outResult != null) { …… } return res; } }}
3. startActivityLocked(1)
1)确保调用者caller的进程是存在的
2)处理FLAG_ACTIVITY_FORWARD_RESULT(这个标志具有跨进程传递的作用,例如:Activity1启动了Activity2,而Activity2启动Activity3时使用了此标志,那么当Activity3调用setResult时,result不会像一般情况那样传递给Activity2,而是传给Activity1)
3)是否找到合适的目标Activity来处理Intent,若没有则直接报错返回
4)检查调用者是否有足够权限来启动指定的Activity
5)调用startActivityUncheckedLocked()处理启动模式和Intent标志
final int startActivityLocked(IApplicationThread caller, Intent intent, String resolvedType, ActivityInfo aInfo, IBinder resultTo, String resultWho, int requestCode, int callingPid, int callingUid, int startFlags, Bundle options, boolean componentSpecified, ActivityRecord[] outActivity){ //step1.判断调用者caller是否为空 if (caller != null) { callerApp = mService.getRecordForAppLocked(caller); if (callerApp != null) { callingPid = callerApp.pid; callingUid = callerApp.info.uid; } else { err = ActivityManager.START_PERMISSION_DENIED; } } …… //step2.处理FLAG_ACTIVITY_FORWARD_RESULT int launchFlags = intent.getFlags(); if ((launchFlags&Intent.FLAG_ACTIVITY_FORWARD_RESULT) != 0 && sourceRecord != null) { // Transfer the result target from the source activity to the new // one being started, including any failures. if (requestCode >= 0) { ActivityOptions.abort(options); return ActivityManager.START_FORWARD_AND_REQUEST_CONFLICT; } resultRecord = sourceRecord.resultTo; resultWho = sourceRecord.resultWho; requestCode = sourceRecord.requestCode; sourceRecord.resultTo = null; if (resultRecord != null) { resultRecord.removeResultsLocked(sourceRecord, resultWho, requestCode); } } //step3.判断是否找到合适的目标Activity来处理Intent if (err == ActivityManager.START_SUCCESS && intent.getComponent() == null) { err = ActivityManager.START_INTENT_NOT_RESOLVED; } if (err == ActivityManager.START_SUCCESS && aInfo == null) { err = ActivityManager.START_CLASS_NOT_FOUND; } if (err != ActivityManager.START_SUCCESS) { if (resultRecord != null) { sendActivityResultLocked(-1, resultRecord, resultWho, requestCode, Activity.RESULT_CANCELED, null); } mDismissKeyguardOnNextActivity = false; ActivityOptions.abort(options); return err; } //step4. 检查调用者是否有足够权限来启动指定的Activity final int startAnyPerm = mService.checkPermission( START_ANY_ACTIVITY, callingPid, callingUid); final int componentPerm = mService.checkComponentPermission(aInfo.permission, callingPid, callingUid, aInfo.applicationInfo.uid, aInfo.exported); if (startAnyPerm != PERMISSION_GRANTED && componentPerm != PERMISSION_GRANTED) { …… } //step5.调用startActivityUncheckedLocked()处理启动模式和Intent标志 err = startActivityUncheckedLocked(r, sourceRecord, startFlags, true, options); return err;}
0 0
- startActivity流程
- StartActivity的流程
- startActivity流程小解
- startActivity()的流程
- AMS--StartActivity流程整理
- Replugin startActivity流程
- Android Activity.startActivity流程简介
- Android Activity.startActivity流程简介
- Android Activity.startActivity流程简介
- Android Activity.startActivity流程简介
- 深入了解startActivity启动流程
- 【Android API】startActivity流程分析
- 从 startActivity 看activity启动流程
- StartActivity
- StartActivity
- startActivity
- StartActivity的流程 Activity组件之一Service--- BindService & unBindService
- Activity启动流程源码分析之startActivity启动(三)
- order by与索引
- 数据库
- Android 内存泄漏总结
- 重建二叉树
- c++ 栈区 堆区 常量区
- startActivity流程
- Android的文件系统结构
- 常见的页面跳转的方法
- OC相关资料
- JVM虚拟机-GC(对象)
- 最近遇到window的坑
- SDWebImage详解
- URL URI File Path 转换(原创)
- Trustzone OP-TEE 在QEMU平台上的编译、运行与测试