I am trying to navigation from DialogFragment
to Fragment
in Navigation Component, but getting weird result.
When I navigate from DialogFragment
to Fragment
, background fragment is changing to target fragment with current dialog on top of it, instead of just moving to target fragment.
Here is the navigation 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/home"
app:startDestination="@+id/titleScreen">
<fragment
android:id="@+id/titleScreen"
android:name="com.example.android.navigationadvancedsample.homescreen.Title"
android:label="@string/title_home"
tools:layout="@layout/fragment_title">
<action
android:id="@+id/action_title_to_about"
app:destination="@id/aboutScreen"/>
</fragment>
<dialog
android:id="@+id/aboutScreen"
android:name="com.example.android.navigationadvancedsample.homescreen.About"
android:label="@string/title_about"
tools:layout="@layout/fragment_about">
<action
android:id="@+id/action_aboutScreen_to_register"
app:destination="@id/register" />
</dialog>
<fragment
android:id="@+id/register"
android:name="com.example.android.navigationadvancedsample.formscreen.Register"
android:label="fragment_leaderboard"
tools:layout="@layout/fragment_leaderboard" />
</navigation>
Why I am getting this behavior or how to fix it?
By fixing I mean normal dialog behavior. Say, I have a dialog D on top of a fragment A and move to a fragment B from a button on D, the screen should show B. And when I pop back from B, it should go to previous stage of D on top of A.
app:popUpTo="@+id/aboutScreen" app:popUpToInclusive="true"
. But you didn't ask for that behavior, you asked for the dialog to come back after you hit the back button, which is not something that is supported and should be filed as a feature request / bug. – TruncatedonActivityResult()
. I was using it with a text field and an option to populate the text field by selecting from a list in another screen. I'm trying to switch from an activity for each screen to a single activity with navigation component and ran into this issue for this one dialog. I would rather keep it a dialog because of how temporary it is and how it relates to the screen it shows over. – Conte