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. T
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()})
There is a question already which is similar to yours. I think this will answer your question:
View the Task's activity stack
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).