Android Jetpack Navigation in multi modular apps
I will be demonstrating about the following topic in Jetpack Navigation
- Using navigation in multi-modular apps
- Using nested fragments in jetpack navigation
helpful when creating bottom navigation view, or having common action bar in some section of app or many more - Source code for the demonstrated project ,
This is a multi-modular single activity project that uses dagger2, clean architecture, room db, Jetpack Navigation


nav_graph_app_module
is the app module’s graph
We will reference this graph in ouractivity_main.xml
, fragment container
We includenav_graph_home_host
here as it is another module and to navigate to that module we simply navigate tonav_graph_home_host
graph
Navigate from splash to homefindNavController().navigate(R.id.nav_graph_home_host)
From splash we will navigate to
nav_graph_home_host
graph,
this graph contains a fragmentHomeHostFragment
HomeHostFragment
contains an bottom nav view and a fragment container
as we are dealing with nested fragment so to avoid stack overflow issue
and also to keep things simple
we will create another graphnav_graph_home
containing all other fragments we need in this module
nav_graph_home
includes multiple graph from different modules
Each graph is associated with menu click of bottom nav view
To achieve navigation we will keep bottom navigation id same as graph’s id
check the Github source code for complete insight
Code to set up bottom navigation with navigation graph
bottonNavView.setupWithNavController(navController)
Now stack is like ::
splash → home
(home will not maintain any stack as navHost is set to default i.e., false)Now if we want to navigate from home to other fragment
but wanted to host from our root nav controller, then can use the below function
/*
`R.id.fragment_container_root` is id of our root fragment
which we inflated in Main Activity
*/val Fragment.findRootNavHost: NavController?
get() = this.activity?.let {
Navigation.findNavController(it, R.id.fragment_container_root)
}
In fragment from where we want to navigate
findRootNavHost?.navigate(`your_destination_fragment`)
I’d like to end this post by saying thank you 🙏 for reading
If have any query we can connect, links in my profile or you can comment it down