0

Hello i have used navigation component and navigation graph to navigate from one fragment to the other what i want is to prevent the onBackPressed completely such that when a use clicks the onBack the app will exit. I am navigating from Register fragment to Home fragment.

Here is the code in navigation graph

<fragment
        android:id="@+id/register_fragment"
        android:name="manu.apps.firebaseloginregister.fragments.RegisterFragment"
        android:label="Register Fragment"
        tools:layout="@layout/register_fragment">

        <action
            android:id="@+id/action_register_to_home_fragment"
            app:destination="@id/home_fragment"/>

    </fragment>

    <fragment
        android:id="@+id/home_fragment"
        android:name="manu.apps.firebaseloginregister.fragments.HomeFragment"
        android:label="Home Fragment"
        tools:layout="@layout/home_fragment">

    </fragment>

Here is my code for navigation in Register fragment when the register button is clicked


Navigation.findNavController(view).navigate(R.id.home_fragment);

Wincelee
  • 21
  • 1
  • 7

1 Answers1

1

You can check this To handle onBackPress. However in your case, i think you want to navigate to Home and clear navigation stack. So you can try Clear stack after navigate.