https://kotlinlang.org logo
Title
r

Remy Benza

02/07/2020, 12:08 PM
which has quite some code to support multiple back stacks.
:google: 2
:stackoverflow: 2
r

Roman Q.

02/07/2020, 12:56 PM
Jetpack Navigation doesn't support multiple backstacks out of the box yet. We use separate (xml) navgraphs with the linked extension and so far it works.
r

Remy Benza

02/07/2020, 2:03 PM
Phew, together with a colleague after couple hours of debugging we found out the order nav graphs id's matter. We first got very weird behavior of multiple fragments on top of each other.
r

Roman Q.

02/07/2020, 2:05 PM
They have to match, yes. ^^
r

Remy Benza

02/07/2020, 2:08 PM
Well the nav graphs id's did match the bottom nav menu id's. But that's not enough. This order also needs to match:
private fun setupBottomNavigationBar() {
    val navGraphIds = listOf(
            R.navigation.feed_nav_graph,
            R.navigation.discover_nav_graph,
            R.navigation.add_experience_nav_graph,
            R.navigation.trips_nav_graph,
            R.navigation.notifications_nav_graph)

    // Setup the bottom navigation view with a list of navigation graphs
    val controller: LiveData<NavController> = binding.globalBottomNav.setupWithNavController(
            navGraphIds = navGraphIds,
            fragmentManager = supportFragmentManager,
            containerId = R.id.global_nav_host_fragment,
            intent = intent
    )
r

Roman Q.

02/07/2020, 2:10 PM
That's what I meant, yep. I remember that Ian Lake said sometime it's necessary to rewrite parts of the fragment in order to support multiple backstacks out of the box. So I guess one has to live with that for now. ^^
f

Freedom

02/08/2020, 1:29 AM
It might messy to use just one activity this is how I break mine down if I have authentication I would create a graph to handle only auth then another graph for dashboard if dashboard has like account section and account has children I,LL create a graph to handle it children
Just to avoid mess and keep a clean code