user316117 user316117 - 1 year ago 46
Android Question

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

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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download