BREMI
BREMI

Reputation: 834

Show Back Stack of Android

For better understanding the behavior of Android I'd like to learn more about the back stack concept. Is there a way to list all activities as they are ordered in back stack. This should also includes all other running tasks.

Upvotes: 20

Views: 16907

Answers (4)

ArpitA
ArpitA

Reputation: 741

You can use android studio profilier for this things. In profilier click on go the memory usage graph, on top of this graph android studio will show all the activies and there lifecycle callbacks like stopped, destoyed etc.

Profiler -> CPU usage graph -> See top which will diplay current activity and callback methods

Upvotes: 0

menno
menno

Reputation: 272

For the back stack of your own app, you can write your own solution 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())
        }
    }
}

Then at any moment you can log it with:

Log.d(TAG, "${ActivityBackStackTracker.getCurrentActivityStack()})

Upvotes: 1

Nebu
Nebu

Reputation: 1362

I have found this information is available in Android Studio (0.5.1): View->Tool Windows->Android. Then on the left hand side select the System Information Icon and from it's drop down select 'Graphics State'. This will dump show a lot of information, but if you scroll down to 'View hierarchy:' you will see the current stack of views i.e. the 'Back Stack'.

The OP did ask about running tasks, so instead if selecting 'Graphics State' select 'Activity Manager State' and you'll find more information (although I found it simpler to view the information in 'Graphics State' for specifically looking at what Activities are in the back stack).

Upvotes: 18

Xazen
Xazen

Reputation: 822

There is a question already which is similar to yours. I think this will answer your question:

View the Task's activity stack

Upvotes: 0

Related Questions