Status Update
Comments
il...@google.com <il...@google.com> #2
The <fragment>
tag is silently doing the wrong thing (using the parentFragmentManager
instead of the childFragmentManager
. As a workaround, you can NavHostFragment
<fragment>
tag.
Description
Version used: 2.3.0-alpha02
Devices/Android versions reproduced on: Galaxy S8 plus
Navigation within Bottom sheet dialog fragment crashes on the second launch.
I have added a navigation host fragment inside the bottom sheet dialog view.
nav_graph_main :
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="
xmlns:app="
android:id="@+id/nav_graph"
app:startDestination="@id/mainFragment">
<fragment
android:id="@+id/homeFragment"
android:name="com.example.testdesign.MainFragment"
android:label="MainFragment" >
<action
android:id="@+id/action_mainFragment_to_childHostFragment"
app:destination="@id/childHostFragment" />
</fragment>
<dialog
android:id="@+id/bottomSheetDialog"
android:name="com.example.testdesign.ChildHostFragment"
android:label="ChildHostFragment" />
</navigation>
nav_graph_bottom_sheet:
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="
xmlns:app="
android:id="@+id/nav_graph"
app:startDestination="@id/firstFragment2">
<fragment
android:id="@+id/firstFragment2"
android:name="com.example.testdesign.FirstFragment"
android:label="FirstFragment" >
<action
android:id="@+id/action_firstFragment2_to_secondFragment2"
app:destination="@id/secondFragment2" />
</fragment>
<fragment
android:id="@+id/secondFragment2"
android:name="com.example.testdesign.SecondFragment"
android:label="SecondFragment" >
<action
android:id="@+id/action_secondFragment2_to_thirdFragment"
app:destination="@id/thirdFragment" />
</fragment>
<fragment
android:id="@+id/thirdFragment"
android:name="com.example.testdesign.ThirdFragment"
android:label="ThirdFragment" />
</navigation>
fragment_bottom_sheet.xml
<RelativeLayout xmlns:android="
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/magenta"
xmlns:app="
xmlns:card_view="
<fragment
android:id="@+id/nav_host_child_host"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:navGraph="@navigation/nav_graph_bottom_sheet"/>
</RelativeLayout>
activity_main.xml
<RelativeLayout xmlns:android="
xmlns:tools="
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="
android:background="@color/new_magenta"
tools:context=".MainActivity">
<fragment
android:id="@+id/nav_host_fragment_main"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_graph_main"/>
</RelativeLayout>
Crash logs :
2020-03-04 01:27:11.094 5254-5254/com.example.testdesign E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.testdesign, PID: 5254
android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
Caused by: java.lang.IllegalArgumentException: Binary XML file line #10: Duplicate id 0x7f08011d, tag null, or parent id 0xffffffff with another fragment for androidx.navigation.fragment.NavHostFragment
at androidx.fragment.app.FragmentLayoutInflaterFactory.onCreateView(FragmentLayoutInflaterFactory.java:116)
at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:135)
at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:356)
at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:335)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.example.testdesign.ChildHostFragment.onCreateView(ChildHostFragment.kt:51)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2698)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:320)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1187)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1356)
at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1434)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1497)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:447)
at androidx.fragment.app.FragmentManager.executeOps(FragmentManager.java:2169)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1992)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1947)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1849)
at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:413)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7050)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)