I have such settings in the project:
apply plugin: 'androidx.navigation.safeargs'
ext.navigationVersion = "1.0.0-beta02"
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:$navigationVersion"
implementation "android.arch.navigation:navigation-fragment-ktx:$navigationVersion" implementation "android.arch.navigation:navigation-ui-ktx:$navigationVersion"
nav_graph.xml:
<fragment
android:id="@+id/loginFragment"
android:name="com.terkacleaning.ui.login.LoginFragment"
android:label="fragment_login"
tools:layout="@layout/fragment_login">
<action
android:id="@+id/action_loginFragment_to_homeFragment"
app:destination="@id/homeFragment"
app:exitAnim="@anim/slide_out_left"
app:popExitAnim="@anim/slide_out_right"
app:popUpTo="@id/loginFragment"
app:popUpToInclusive="true" />
</fragment>
<fragment
android:id="@+id/homeFragment"
android:name="com.terkacleaning.ui.home.HomeFragment"
android:label="fragment_home"
tools:layout="@layout/fragment_home"/>
Methods are generated:
LoginFragmentDirections.actionLoginFragmentToHomeFragment()
But these methods don't work
As per the Safe Args documentation, constructing a NavDirections
object isn't enough - you need to pass it to navController.navigate()
:
navController.navigate(
LoginFragmentDirections.actionLoginFragmentToHomeFragment())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With