It’s simple to get the list of destinations that’s currently in your back stack. The only thing you need is a reference to the Navigation Component’s NavController
.
The NavController
object has a backQueue
property that you can inspect.
backQueue
is an array, and each item’s destination property is what you’re probably looking for!
To show my current Navigation’s back stack, I use Android Studio’s Debugger, and create watches such as the following:
I haven’t literally tried, but logging them programmatically like so should work too:
1 2 3 4 5 6 |
for(item in navController.backQueue){ Log.d("MyNavigationBackStack", "item.destination.displayName: ${item.destination.displayName}") } Log.d("MyNavigationBackStack", "navController.backQueue: ${navController.backQueue}") Log.d("MyNavigationBackStack", "navController.currentBackStackEntry.destination.displayName: ${navController.currentBackStackEntry.destination.displayName}") Log.d("MyNavigationBackStack", "navController.currentDestination: ${navController.currentDestination}") |
Lemme know if these work, or if you have relevant tips that haven’t been mentioned!