Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of my app's tasks and the stack of their Activities?

Tags:

android

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.

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?

Thanks in advance.

like image 748
user316117 Avatar asked Apr 09 '13 16:04

user316117


2 Answers

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.

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?

You don't, strictly speaking.

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.

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.

like image 200
CommonsWare Avatar answered Sep 24 '22 02:09

CommonsWare


If you have access to adb, you can use below command to view all tasks and stacks available.

adb shell am stack list
like image 42
Fazil Avatar answered Sep 23 '22 02:09

Fazil