0

I'm using Android Navigation Component. There is one activity with FragmentContainerView(NavHostFragment) with simple navigation flow by common_navigation_graph But on one fragment there is a nested NavHostFragment and BottomNavigationView. Reason for that - I want to have 3 tabs on the fragment. Bottom navigation configure with own navController and separate navigation_graph

val navController = activity?.findNavController(R.id.navHostViewPagerView)
binding?.bottomNavigation?.setupWithNavController(navController!!)

On each Tab there is a one more nested fragment with own FragmentContainerView and it's own small tab_navigation_graph Navigation scheme looks: [enter image description here][1]
[1]: https://i.sstatic.net/gmXOY.png

In general it works pretty well. Navigation between tabs, navigation in some selected Tab works well, back stack works well

override fun handleOnBackPressed() {    
    view?.findNavController()?.popBackStack()
}

But since there was a navigation to some next fragment from common_navigation_graph(SomeNextFragment on the picture) the backStack flow will be broken. I will be able to return to fragment with Tabs, but backStack flow for nested fragments in the Tab will not work. Only the last fragment will be displayed(Tab1.2) Transition by Blue arrow not working.

On handleOnBackPressed() view==null and fragment.id==0. Fragment was destroyed

Question is how to save ability to navigate through nested Tab fragments on come back from other fragmnet from common_navigation_graph

1 Answer 1

0

Each tab should hold its own back stack.

https://github.com/googlesamples/android-architecture-components/tree/master/NavigationAdvancedSample

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Davit. You are right. Looking on it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.