Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safeargs generated directions do not work (Android)

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

like image 317
Vüsal Guseynov Avatar asked Mar 04 '23 08:03

Vüsal Guseynov


1 Answers

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())
like image 93
ianhanniballake Avatar answered Mar 15 '23 10:03

ianhanniballake