So I've already read most of https://developer.android.com/guide/navigation/navigation-multi-module#groovy and fairly understand how to implement nav_graph and stuff. But I kinda have a bit of a complex use-case that I don't have a concrete idea on how to implement.
In my app, I'll be having a structure that looks like this:
Module 1-
|-Module1_Frag1
|-Module1_Frag1_SubFrag1
|-Module1_Frag1_SubSubFrag1
|...
|...
Module 2-
|-Module2_Frag1
|-Module2_ViewPager1
|-Module2_Frag1_SubFrag1
|-Module2_Frag1_SubFrag1_SubFrag1
|-Module2_Frag1_SubFrag2
|-Module1_Frag1_SubFrag2_SubFrag1
I'm planning to use DrawerLayout, hence the structure. I know Module 1 is easy to do, but I don't know what to do with Module 2. How should I structure the nav_graph for that? Do I need multiple NavHostFragment for that?
I found ideas from the Navigation Drawer Views Activity template. I basically just copied what's in there except for the
nav_graphof course. So basically, every screen you have needs to be in a fragment so you can put it inside afragmentas that's how this wholeNavigationsystem works.As I mentioned above on my question, I was going to put the
ViewPagerin aFragmentwhich I didn't completely know was the right move initially was actually what I needed. The only changes that I have to do was transfer some of my code inActivitys toFragments so I can easily add them on thenav_graph. Then after that was kinda simple. I tried to have multiplenav_graphs then one mainnav_graphthatincluded does small ones, but doesn't seem to work. So I just combined them in the end. Here's what my finalnav_graphlooks like:What's kinda weird that I realized in the end, it seems like that I actually need to have the same id for the
MenuItemthat corresponds to the module and the id for starting "routes" in thenav_graph. Android Studio detects this and I have to accept aDialogthat popped up mentioning the fact. Here's my finalmenufor the drawer:And that's it