Get Navigation Component destinations in back stack // Android Kotlin Dev Diary

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:

Screenshot taking when no frames were available, and thus the texts are red…

I haven’t literally tried, but logging them programmatically like so should work too:

Lemme know if these work, or if you have relevant tips that haven’t been mentioned!

Related Posts:

Posts that may be related to "Get Navigation Component destinations in back stack // Android Kotlin Dev Diary":

Catzie

A Filipino programmer with a variety of interests such as baking, singing, making up silly song/rap lyrics, K-pop, drawing, creating unique dessert flavors, obsessing about finding out how some things works, board games, anime, video games, and forgetting things that usually go in her long list of interests. Running small-time online dessert shops Cookies PH and Catzie's Cakery.

Leave a Reply

Your email address will not be published. Required fields are marked *