Navigating with Jetpack Compose
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.