如何确认新任务中是否启动了SubActivity?

技术如何确认SubActivity是不是在新的任务中启动这篇文章主要讲解了“如何确认SubActivity是不是在新的任务中启动”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学

这篇文章主要讲解了"如何确认子活动是不是在新的任务中启动",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"如何确认子活动是不是在新的任务中启动"吧!

机器人源代码工程为我们准备了(同亚洲开发银行)亚洲开发银行工具。

可以查看模拟器上系统运行的状况。

执行下面的命令查看:

[html]viewpropyuser-NAME @ MAChine-NAME : ~/Android $ adbshelldumpsystimity这个命令输出的内容比较多,这里我们只关心任务记录部分:[html]viewpranpyrisingactivities ostrecentfirst):任务记录{ 4070 D8 F8 # 3 ashy。lo。任务}运行# 2:历史记录{ 406 a13 F8害羞。lo。任务/.子活动}运行# 1:历史记录{ 406 a0e 00 shy。lo。任务/.主要活动}任务记录。安卓。启动器}运行# 0:历史记录{ 40677518m。安卓。启动器/com。安卓。发射器2。启动器}果然,子活动和主要活动都是运行在任务记录#3中,并且子活动在主要活动的上面。这是怎么回事呢?碰到这种情况莱纳斯托瓦尔兹告诫我们:读他妈的源代码;去年张麻子又说:枪在手,跟我走;我们没有枪,但是有源代码,因此,我要说:跟着代码走。

前面我们在两篇文章机器人应用程序启动过程源代码分析和机器人应用程序内部启动活动过程(开始活动)的源代码分析时,分别在第九步和第八步中分析了活动在启动过程中与任务相关的函数activitystack。startactivityncyccheckdlocked函数中,它定义在框架/基础/服务/Java/com/Android/server/am/activity stack。Java 语言(一种计算机语言,尤用于创建网站)文件中:

[Java]ViewPlainCopyPublicClassactivityStack {.finalintstaractivitycyccheckd locked(activityrencordsorder,ActivityRecordsourceRecord,Uri[],grantedUriPermissions,intgrantedMode,booleanonlyIfNeeded,booleandorsume){ finalintintent=r . intent;finalincalinguid=r . launchedfrouid;int启动标志=意图。getflags();activityrencrdnottop=(launchFlagsIntent .FLAG_ACTIVITY_PREVIOUS_IS_TOP)!=0?r:null.if(源记录==null){ 0.} else if(源记录。启动模式==活动信息.LAUNCH _ SINGLE _ INSTANCE){ 0.} else if(r . launchmode==活动信息.发射_单一_实例| | r .发射模式==Acti

vityInfo.LAUNCH_SINGLE_TASK) { // The activity being started is a single instance... it always // gets launched into its own task. launchFlags |= Intent.FLAG_ACTIVITY_NEW_TASK; } ...... boolean addingToTask = false; if (((launchFlags&Intent.FLAG_ACTIVITY_NEW_TASK) != 0 && (launchFlags&Intent.FLAG_ACTIVITY_MULTIPLE_TASK) == 0) || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK || r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) { // If bring to front is requested, and no result is requested, and // we can find a task that was started with this same // component, then instead of launching bring that one to the front. if (r.resultTo == null) { // See if there is a task to bring to the front. If this is // a SINGLE_INSTANCE activity, there can be one and only one // instance of it in the history, and it is always in its own // unique task, so we do a special search. ActivityRecord taskTop = r.launchMode != ActivityInfo.LAUNCH_SINGLE_INSTANCE ? findTaskLocked(intent, r.info) : findActivityLocked(intent, r.info); if (taskTop != null) { ...... if ((launchFlags&Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0 || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK || r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) { // In this situation we want to remove all activities // from the task up to the one being started. In most // cases this means we are resetting the task to its // initial state. ActivityRecord top = performClearTaskLocked( taskTop.task.taskId, r, launchFlags, true); if (top != null) { ...... } else { // A special case: we need to // start the activity because it is not currently // running, and the caller has asked to clear the // current task to have this activity at the top. addingToTask = true; // Now pretend like this activity is being started // by the top of its task, so it is put in the // right place. sourceRecord = taskTop; } } else if (r.realActivity.equals(taskTop.task.realActivity)) { ...... } else if ((launchFlags&Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) == 0) { ...... } else if (!taskTop.task.rootWasReset) { ...... } ...... } } } ...... if (r.packageName != null) { // If the activity being launched is the same as the one currently // at the top, then we need to check if it should only be launched // once. ActivityRecord top = topRunningNonDelayedActivityLocked(notTop); if (top != null && r.resultTo == null) { if (top.realActivity.equals(r.realActivity)) { if (top.app != null && top.app.thread != null) { ...... } } } } else { ...... } boolean newTask = false; // Should this be considered a new task? if (r.resultTo == null && !addingToTask && (launchFlags&Intent.FLAG_ACTIVITY_NEW_TASK) != 0) { // todo: should do better management of integers. mService.mCurTask++; if (mService.mCurTask <= 0) { mService.mCurTask = 1; } r.task = new TaskRecord(mService.mCurTask, r.info, intent, (r.info.flags&ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH) != 0); if (DEBUG_TASKS) Slog.v(TAG, "Starting new activity " + r + " in new task " + r.task); newTask = true; if (mMainStack) { mService.addRecentTaskLocked(r.task); } } else if (sourceRecord != null) { if (!addingToTask && (launchFlags&Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) { ...... } else if (!addingToTask && (launchFlags&Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) != 0) { ...... } // An existing activity is starting this new activity, so we want // to keep the new one in the same task as the one that is starting // it. r.task = sourceRecord.task; ...... } else { ...... } ...... startActivityLocked(r, newTask, doResume); return START_SUCCESS; } ...... }

感谢各位的阅读,以上就是“如何确认SubActivity是不是在新的任务中启动”的内容了,经过本文的学习后,相信大家对如何确认SubActivity是不是在新的任务中启动这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是,小编将为大家推送更多相关知识点的文章,欢迎关注!

内容来源网络,如有侵权,联系删除,本文地址:https://www.230890.com/zhan/151643.html

(0)

相关推荐

  • 张飞穿针的歇后语是什么,大眼瞪小眼”比喻什么意思

    技术张飞穿针的歇后语是什么,大眼瞪小眼”比喻什么意思有一次,张飞正要率军出发,却被 夫人叫住,拿出一根绣花针,一根红纱 线,非要张飞帮她把线穿上才能走。张飞听了哈哈大笑:“穿针引线,虽是 女人干的活,但也难不住我张飞穿针

    生活 2021年10月27日
  • testflight 已移除测试人员(iphone testflight)

    技术iOS真机调试TestFlight安装及提交App Store审核的示例分析这篇文章主要介绍iOS真机调试TestFlight安装及提交App Store审核的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣

    攻略 2021年12月20日
  • AspNetCore应用注意哪些点

    技术AspNetCore应用注意哪些点今天就跟大家聊聊有关AspNetCore应用注意哪些点,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。背景已经有很多文章记录了

    攻略 2021年11月18日
  • Java中boolean占几字节

    技术Java中boolean占几字节这篇文章主要介绍“Java中boolean占几字节”,在日常操作中,相信很多人在Java中boolean占几字节问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家

    攻略 2021年11月4日
  • 的分析(得分相同怎么排名)

    技术如何进行Microsoft Office内存损坏漏洞CVE–2017–11882的分析如何进行Microsoft Office内存损坏漏洞CVE–2017–11882的分析,针对这个问题,这篇文章详细介绍了相对应的分

    攻略 2021年12月21日
  • currentTimeMillis和getTimeInMillis与getTime获取当前时间戳耗时比较是怎样的

    技术currentTimeMillis和getTimeInMillis与getTime获取当前时间戳耗时比较是怎样的这期内容当中小编将会给大家带来有关currentTimeMillis和getTimeInMillis与g

    攻略 2021年10月20日