Member-only story

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

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

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) from India 🇮🇳

Responses (2)

Write a response

The place where you say - "Here if you don’t use navigateUp() function instead of , you use navigate("first") function to get back to the previous screen then it will add the first and second screen multiple times to the backstack ."
You said we need…

Using hilt view model it will be more easier.