Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
467 views
in Technique[技术] by (71.8m points)

android - Issue with Back stack flow using Navigation component and BottomNavigationView

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.stack.imgur.com/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

question from:https://stackoverflow.com/questions/65844360/issue-with-back-stack-flow-using-navigation-component-and-bottomnavigationview

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...