I made some fragments and a nav_Graph and using setOnClickListener on some button and actions from nav_Graph to move between the fragments but when I press the back button it will close the app how can I fix that ?
the nav_graph
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/login_register_graph"
app:startDestination="@id/introdcutionFragment">
<fragment
android:id="@+id/introdcutionFragment"
android:name="com.example.go.ui.fragment.IntrodcutionFragment"
android:label="IntrodcutionFragment"
tools:layout="@layout/fragment_introdcution">
<action
android:id="@+id/action_introdcutionFragment_to_accountOptionsFragment"
app:destination="@id/accountOptionsFragment" />
</fragment>
<fragment
android:id="@+id/loginFragment"
android:name="com.example.go.ui.fragment.LoginFragment"
android:label="LoginFragment"
tools:layout="@layout/fragment_login">
<action
android:id="@+id/action_loginFragment_to_registerFragment2"
app:destination="@id/registerFragment"
app:popUpTo="@id/accountOptionsFragment" />
</fragment>
<fragment
android:id="@+id/registerFragment"
android:name="com.example.go.ui.fragment.RegisterFragment"
android:label="RegisterFragment"
tools:layout="@layout/fragment_register">
<action
android:id="@+id/action_registerFragment_to_loginFragment2"
app:destination="@id/loginFragment"
app:popUpTo="@id/accountOptionsFragment" />
</fragment>
<fragment
android:id="@+id/accountOptionsFragment"
android:name="com.example.go.ui.fragment.AccountOptionsFragment"
android:label="AccountOptionsFragment"
tools:layout="@layout/fragment_account_options">
<action
android:id="@+id/action_accountOptionsFragment_to_loginFragment"
app:destination="@id/loginFragment" />
<action
android:id="@+id/action_accountOptionsFragment_to_registerFragment"
app:destination="@id/registerFragment" />
</fragment>
</navigation>
here's the way I move for all of the fragments
binding.buttonStart.setOnClickListener {
findNavController().navigate(R.id.action_introdcutionFragment_to_accountOptionsFragment)
}
the rest is default like didn't added code in the activity I cant think of what code you might need to see in my project (if I know what part of the code is wrong ...) so if you need to see a file leave a comment thx.