Lors de l'utilisation en androidx.fragment.app.FragmentContainerViewtant que navHost au lieu d'une fragmentapplication standard, il n'est pas possible de naviguer vers une destination après un changement d'orientation.
J'obtiens une erreur suivante:
java.lang.IllegalStateException: no current navigation node
Existe-t-il un problème que je devrais connaître pour l'utiliser correctement ou ma façon d'utiliser les composants de navigation est-elle incorrecte?
Activité simple xml avec une vue:
...
<androidx.fragment.app.FragmentContainerView
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:navGraph="@navigation/nav_simple" />
...
Code de navigation:
<?xml version="1.0" encoding="utf-8"?>
<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/nav_legislator.xml"
app:startDestination="@id/initialFragment">
<fragment
android:id="@+id/initialFragment"
android:name="com.example.fragmenttag.InitialFragment"
android:label="Initial Fragment"
tools:layout="@layout/initial_fragment">
<action
android:id="@+id/action_initialFragment_to_destinationFragment"
app:destination="@id/destinationFragment" />
</fragment>
<fragment
android:id="@+id/destinationFragment"
android:name="com.example.fragmenttag.DestinationFragment"
android:label="Destination Fragment"
tools:layout="@layout/destination_fragment" />
</navigation>
Voici un dépôt github où vous pouvez facilement reproduire un bug: https://github.com/dmytroKarataiev/navHostBug
<fragmentdans un fichierFragmentContainerView.