Jetpack Compose Navigation Architecture

Saqib
Android Tech Stack
Published in
8 min readJan 9, 2023

--

Photo by Joseph Barrientos on Unsplash

Lets go through Navigation Component in Compose with an example code and write UI Tests for Navigation Component.

Navigation in Compose has the same key parts as traditional View base Navigation, lets see basic description and will go in details further down

  • Navigation Graph: It specifies composable destinations that user can navigate between, each composable destination is associated with route, route is unique key defines each composable destination.
  • NavHost: Its a composable which specifies all possible composable destinations inside using composable keyword. As user navigates between different composable destinations, NavHost content is recomposed to show corresponding composable.
  • NavigationController: It manages all navigations inside NavHost, It navigates to individual destinations and shows up corresponding composable screen. Its stateful and keeps track of back stack of compostables used in navigations and the states

you do not need to use requireActivity to get NavController, you can create it via Api rememberNavController() in composable.

What is route?

route is a key used to defined each composable destination where you can navigate to using navController, you can think of it as a deep link to the…

--

--

Saqib
Android Tech Stack

Senior Mobile Engineer (Android & iOS) , Berlin | Sharing my development experience