Joao Birk
09/23/2020, 2:15 PMdismiss()
findNavController().navigate(
R.id.action_bottom_sheet_b,
bundleOf(...)
)
It opens the Bottom Sheet B without any problem, but if I rotate the screen I get a crash:
java.lang.IllegalStateException
DialogFragment NUM doesn't exist in the FragmentManager
If I move the dismiss
after the navigate
, Bottom Sheet B doesnt show up. Seems they are in the same transaction and therefore bottom sheet B gets dismised as well.
Here is my navigation.xml
<dialog
android:id="@+id/bottom_sheet_a"
android:name="...BottomSheetA"
tools:layout="@layout/dialog_bottom_sheet_a">
<action
android:id="@+id/action_bottom_sheet_b"
app:destination="@id/bottom_sheet_b"/>
</dialog>
I found this on stack: https://stackoverflow.com/questions/56647476/why-dialog-does-not-have-a-navcontroller-missing
And this: https://issuetracker.google.com/issues/134089818 which seems got resolved in 2.1.0-alpha06
But not sure it's the same issue. I'm using 2.3.0.
If I use child childFragmentManager.beginTransaction().show()
to show bottom sheet A instead of findNavController().navigate()
, bottom sheet B gets displayed fine, no crash either.
Any ideas of how to fix this?Ian Lake
09/23/2020, 3:09 PMdismiss()
is asynchronous and doesn't inform the NavController
until after the navigate()
already updates the state. You want findNavController().popBackStack()
which does synchronously update the NavController
instead. Or just add a popUpTo
to your action: https://developer.android.com/guide/navigation/navigation-navigate#popJoao Birk
09/23/2020, 5:42 PM