Issue
A similar question was asked before however this seems to be a different issue.
Using the Navigation component, I define a dialog like so:
<navigation
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_graph"
app:startDestination="@id/main_fragment">
<fragment
android:id="@+id/main_fragment"
android:name="com.example.app.MainFragment"
android:label="MainFragment" />
<dialog
android:id="@+id/dialog_fragment"
android:name="com.example.app.DialogFragment"
android:label="AddFeeling" />
</navigation>
In the MainFragment
I have a button that runs navController.navigate(R.id.dialog_fragment)
. This opens the dialog fine. When I swipe the dialog fragment away and click the button again, the app crashes.
The crash is caused by including a fragment inside of the dialog. I technically have a NavHostFragment
inside of the dialog fragment, but even putting a standard fragment in the app crashes. If I have no fragments inside the dialog it works fine.
Here is the dialog fragment layout. As you can see the <fragment>
attribute is where the duplicate is:
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/bottom_sheet_dialog"
android:layout_width="match_parent"
android:layout_height="match_parent"
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize
app:layout_constraintTop_toTopOf="parent" />
<fragment
android:id="@+id/dialog_nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar"
app:navGraph="@navigation/dialog_graph" />
</androidx.constraintlayout.widget.ConstraintLayout>
Any ideas to what the issue could be? Thanks
Solution
Similar to the question linked in mine, the fragment of the NavHostFragment must not have an ID either, the inflater will notice the fragment has an ID so it will flag it as a duplicate.
Answered By - Pav Sidhu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.