1

I'm trying to create an app ("ShowStack") to view the current App Back Stack (for development purposes). I know it can be done by using adb with the command "adb shell dumpsys activity activities". I tried using ActivityManager functions getAppTasks() and getRunningProcesses, etc. But these only return a list of 1 item, the current app/task "ShowStack", which I already knew thank you.

How can I view all tasks/activities?

2 Answers 2

0

There's no API that lets you peek the whole backstack. Unless you are targeting rooted devices, you are most likely out of luck as there's no way to inspect that for security/privacy reasons.

Sign up to request clarification or add additional context in comments.

1 Comment

Well, how come dumpsys works then? I'm almost certain adb shell does not run as root.
0

You can write your own using Application.ActivityLifecycleCallbacks:

class MyApp : Application() {
   
   override fun onCreate() {
      super.onCreate()
      ActivityBackStackTracker.install(this)
   }
}

class ActivityBackStackTracker : Application.ActivityLifecycleCallbacks {

    override fun onActivityCreated(activity: Activity, bundle: Bundle?) {
        activityStack.add(activity::class)
    }

    override fun onActivityDestroyed(activity: Activity) {
        activityStack.remove(activity::class)
    }

    //..

    companion object {
        private val activityStack = mutableListOf<KClass<out Activity>>()

        fun getCurrentActivityStack() = listOf(activityStack)

        fun install(app: Application) {
            app.registerActivityLifecycleCallbacks(ActivityBackStackTracker())
        }
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.