4

I'm looking for Navigation Architecture component and all examples i've seen are about single Activity app with integration of android bottom menu, so i would like to know if this component can be useful for my situation. My app look like: A SplashActivity that download some data, and if is all ok, launch Main activity. A MainActivity with a custom bottom navigation that allow user to navigate to 3 different sections of app (A,B,C), and inside each section user can navigate deeper iside section itself:

section A: FragmentAOne -> FragmentATwo -> FragmentAThree

section B: FragmentBOne -> FragmentBTwo

section C: FragmenCOne -> FragmentCTwo -> FragmentCThree

and from some of that fragment in some case user can open Another activity that show a fullscreen webview.

Now, i need that each section is independent from others (each fragment should have its backstack), so user can be inside FragmentAThree, navigate to FragmentCOne and come back to section A and still stay inside FragmentAThree.

Can Navigation Architecture component handle this strange situation?

giozh
  • 9,868
  • 30
  • 102
  • 183

1 Answers1

0

This can be achieved with the latest navigation component, you will need to set top level destinations like so:

    val drawerLayout : DrawerLayout? = findViewById(R.id.drawer_layout)
    appBarConfiguration = AppBarConfiguration(
            setOf(R.id.FragmentAOne, R.id.FragmentBOne, R.id.FragmenCOne),
            drawerLayout)

Destinations reachable via global navigation UI, such as bottom nav or side nav, all appear to users as on the same top level of the hierarchy. Therefore, they are top level destinations. FragmentAOne, FragmentBOne and FragmenCOne are in the bottom nav and we want the drawer icon to show on both of these destinations, so they are top-level destinations.

Note that the start destination is always considered a top-level destination. If you don't specify a list of top-level destinations, then the only top-level destination is your start destination. You can learn more about AppBarConfiguration in the documentation.

You can read and experiment with this in the navigation codelab https://codelabs.developers.google.com/codelabs/android-navigation

Calin
  • 6,661
  • 7
  • 49
  • 80