I am using Navigation library (2.2.0-rc04) and I have two DialogFragments. First one is A, opened from MainFragment
. Second one is B and it is just an alert dialog for confirmation opened by A. Here is the the overall structure of the related navigation XML:
<navigation app:startDestination="@id/mainFragment" ...>
<fragment android:id="@+id/mainFragment" ...>
<action
android:id="@+id/action_mainFragment_to_ADialog"
app:destination="@id/ADialog" />
</fragment>
<dialog
android:id="@+id/ADialog"
android:name="com...ADialog"
android:label="ADialog"
tools:layout="@layout/dialog_a">
<action
android:id="@+id/action_aDialog_to_bDialog"
app:destination="@id/BDialog" />
</dialog>
<dialog
android:id="@+id/BDialog"
android:name="com...BDialog"
android:label="BDialog" />
<action
android:id="@+id/action_global_login"
app:destination="@id/nav_graph_login"
app:popUpTo="@id/mainFragment"
app:popUpToInclusive="true"/>
</navigation>
I want to have only one dialog appearing in the screen at a time. Therefore, when user taps a button on A to go to B, I call dismiss()
on A right before I call navigate(action_aDialog_to_bDialog)
to pop up B. B pops up but when I try to call navigate(action_global_login)
from B, I get following error:
IllegalStateException: Fragment B not associated with a fragment manager.
Any ideas what the problem is and how to solve it?