Navigating with Jetpack Compose

Jayant Kumar🇮🇳
10 min readApr 28, 2023
Photo by Jamie Street on Unsplash

In this article we are going to learn how we can navigate from one screen (composable function) to another screen or any activity in jetpack compose.

For that we have to include one library in your build.gradle file.

dependencies {
def nav_version = "2.5.3"

implementation("androidx.navigation:navigation-compose:$nav_version")
}

Before moving to the actual code , let’s learn about some topics which will be responsible for the navigation.

NavHostController

This person plays a very important role in navigation , when you navigate from one screen to another screen this will keep track the back stack of composable function and also keep the state of each screen.

Through rememberNavController() composable function we make navHostController .

val navController = rememberNavController()

Key Features of NavHostController

  • it provide methods for navigating between different destinations.
  • it manages the back stack of composable functions.
  • it provide methods for passing data between screens.

NavHost

--

--

Jayant Kumar🇮🇳
Jayant Kumar🇮🇳

Written by Jayant Kumar🇮🇳

Hello My name is Jayant Kumar, I am a software Engineer , specialist in Mobile Development (Android , IOS , Flutter , React Native and Ionic) from India 🇮🇳

Responses (2)