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.
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.
If you have access to adb, you can use below command to view all tasks and stacks available.
adb shell am stack list
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With