I have an unexpected (to me at least) behaviour with
OnDestinationChangedListener
of the Navigation component. I have a bottom nav bar with 3 items, and the third is a subgraph. When I navigate to that one my OnDestinationChangedListener gets called twice, first with the start destination and then with the actual destination.
Is this the intended behaviour?
✔️ 1
Jordi Saumell
02/06/2021, 4:57 PM
Also, what I am trying to achieve, in case someone has a better solution:
When I click on one of the bottom items I save the route of destination in an observable so that I can use it to know which item should be highlighted.
This does not work when using the system back, so I added a
OnDestinationChangedListener
to detect when the start destination was opened and update the observable with the start destination. As the
OnDestinationChangedListener
goes through the start destination, it breaks my solution.
style shown there, you won't get any intermediate state such as the start destination being dispatched like you would if you did it with a separate
popBackStack()
followed by a
navigate()
j
Jordi Saumell
02/06/2021, 5:14 PM
Thank you, it seems to work! How are you so fast??
Also, is this new or sort of new? I diverged from the implementation of the documentation because I would get 2 start destinations on the backstack, and another issue I do not remember right now