This is the second part of the complete mini course on navigation component. In this tutorial, you will learn how to send data from one fragment to another fragment using Safe Args in navigation component in your application. Safe Args is strongly recommended for navigating and passing data between fragments because it prevents data type mismatch errors and app crashes.
Add Dependency
******************
dependencies {
def nav_version = "2.3.0-alpha04"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
}
Compile Options
******************
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
Kotlin Plugin
**************
apply plugin: "androidx.navigation.safeargs.kotlin"
The navigation component consists of three keywords that are described as bellow:
1- Navigation Graph: is a resource file that contains all of your destinations and actions. The graph represents all of your app's navigation paths.
2- NavHost: is an empty container that displays destinations from your navigation graph. The navigation component contains a default NavHost implementation, NavHostFragment, that displays fragment destinations.
3- NavController: its an object that manages app navigation within a NavHost. This would help to replace one fragment with another fragment in the NavHost container.
🔴 Subscribe for more educational tutorials on CodeWithMazn channel!
Follow me on Instagram
/ codewithmazn