I use navigation library and safeargs for passing data. I define argument to fragment like that.
Follow these steps:
Step 1: Add dependencies
def nav_version = "2.3.2"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
Step 2: In your app-level
build.gradlemake sure you have below plugins added.
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'kotlin-android-extensions'
id 'androidx.navigation.safeargs.kotlin'
}
Step 3: Add this in project_level
build.gradleinside dependencies section :
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.2"
Step 4: In your
nav_graph.xmlmake sure to connect one fragment to another withactions.Step 5: Clean & Rebuild your project.