如何获取我的应用程序任务及其活动堆栈的列表? [英] How to get a list of my app's tasks and the stack of their Activities?

查看:71
本文介绍了如何获取我的应用程序任务及其活动堆栈的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了更好地了解活动,任务,每个任务的后堆栈以及不同的launchModes之间的关系,我想编写一个包含约7个活动的应用程序,并在3个任务中运行,其中活动以不同的launchModes启动,并且在运行时,我想显示每个活动的堆栈,并在我浏览应用程序并启动或关闭其他活动时观看它们的变化.

In order to better understand the relationship between Activities, tasks, the back-stack for each task, and different launchModes I want to write an app with about 7 Activities, running in 3 tasks, where the Activities are launched in different launchModes, and as I'm running I want to display the stacks for each activity and watch them change as I navigate through my app and launch or close different Activities.

如何获取当前应用程序的所有任务的列表,然后在这些任务的堆栈上获取活动? ActivityManager类使我可以根据最近或正在运行的内容查询任务信息但是如何仅查询当前应用程序的任务信息?

How can I get a list of all the Tasks for my current application and then get the Activities on those tasks' stacks? The ActivityManager class lets me query task info based on what's recent or what's running but how do I query task info just for my current app?

谢谢.

推荐答案

如何获取当前应用程序的所有任务的列表

How can I get a list of all the Tasks for my current application

没有这样的概念.任务可以包含来自应用程序的活动.打个比方,没有网站拥有浏览器选项卡的后堆栈,尽管网站的页面可能位于浏览器选项卡的后堆栈中.

There is no such concept. Tasks can contain activities from an application. To drawn an analogy, no Web site owns the back stack of a browser tab, though a Web site's pages may be in the back stack of a browser tab.

然后在这些任务的堆栈上获取活动?

then get the Activities on those tasks' stacks?

这是不可能的,因为活动不一定全部来自您的过程.

That is not possible, as the activities are not necessarily all from your process.

ActivityManager类可让我根据最近或正在运行的内容查询任务信息,但是如何仅针对当前应用程序查询任务信息?

The ActivityManager class lets me query task info based on what's recent or what's running but how do I query task info just for my current app?

严格来说,您不会.

您可以遍历正在运行的任务,并且可以找到那些活动之一是 baseActivity topActivity 的活动,基于这些 ComponentName 值.

You can iterate over the running tasks, and you can find those where one of your activities is the baseActivity or the topActivity based on those ComponentName values.

或者,您的活动知道其任务ID,该任务ID是通过获得的通过 getTaskId() .如果需要,您可以在运行的任务中找到这些任务,并与ID值匹配,以查找有关活动任务的任务级详细信息.

Or, your activities know their task ID, obtained via getTaskId(). If you need to, you can find those tasks in the running tasks, matching up the ID values, to find out task-level details about the activity's task.

这篇关于如何获取我的应用程序任务及其活动堆栈的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆