I just set up a projet with Android navigation component and here's the structure of my 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/nav_graph"
app:startDestination="@id/a">
<fragment
android:id="@+id/a"
android:name="com.example.tutorial.fragmentA"
android:label="a">
<action android:id="@+id/action_a_to_b"
app:destination="@id/b"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim"/>
</fragment>
<fragment
android:id="@+id/b"
android:name="com.example.tutorial.fragmentB"
android:label="b">
</fragment>
</navigation>
In fragment A I navigate to B like this:
findNavController().navigate(R.id.action_a_to_b)
In fragment B, I have a custom toolbar and the idea is that a click on the top left arrow should close fragment B and resume A:
(activity as AppCompatActivity).setSupportActionBar(binding.toolbar)
binding.toolbar.setNavigationOnClickListener {
findNavController().popBackStack()
}
Same goes if I click on the Key down press button:
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner){
findNavController().popBackStack()
}
The problem I'm still stuck in fragment B: the exit animation starts and ends and I'm still in fragment B. Any ideas how to go about to fix this ?