Navigation Component
Manage multi-screen navigation with a visual NavGraph, Safe Args for type-safe arguments, NavController, and deep link support.
What Is the Navigation Component?
The Navigation Component is an Android Jetpack library that manages fragment navigation, back stack, deep links, and transition animations in a single, visual graph.
Key benefits:
- Visual navigation graph in Android Studio
- Type-safe argument passing (Safe Args)
- Automatic back stack management
- Deep link support out of the box
Setup: Dependencies
Add to app/build.gradle:
// app/build.gradle
dependencies {
implementation 'androidx.navigation:navigation-fragment-ktx:2.7.7'
implementation 'androidx.navigation:navigation-ui-ktx:2.7.7'
}
// project/build.gradle (for Safe Args):
buildscript {
dependencies {
classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.7.7'
}
}
// app/build.gradle — apply the plugin:
plugins {
id 'androidx.navigation.safeargs.kotlin'
}