I implemented a navigation structure using two nested NavHostFragments
s. I want the back button to first pop the navigation stack of the child Fragment
's navigation graph, and then once back to the start, pop the parent Fragment
's graph. This behaviour works when I set app:defaultNavHost="true"
for both the parent and child FragmentContainerView
s.
But according to the Android documentation:
The
app:defaultNavHost="true"
attribute ensures that yourNavHostFragment
intercepts the system Back button. Note that only oneNavHost
can be the default. If you have multiple hosts in the same layout (two-pane layouts, for example), be sure to specify only one defaultNavHost
.
Is this rule still applicable when using nested NavHost
s?
What problems could I run into when setting defaultNavHost="true"
for multiple/nested NavHost
s?