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

An odd human being who happens to have a variety of ever-changing interests, but right now they are programming, making up silly song/rap lyrics, K-pop, drawing, creating unique dessert/drink flavors, obsessing about finding out how some things works, automation, anime, video games... Ran online dessert shops Cookies PH and Catzie's Cakery in her past life.

Leave a Reply

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