Bei Verwendung androidx.fragment.app.FragmentContainerViewals navHost anstelle einer normalen fragmentApp kann nach einer Änderung der Ausrichtung nicht zu einem Ziel navigiert werden.
Ich erhalte folgende Fehlermeldung:
java.lang.IllegalStateException: no current navigation node
Gibt es ein Problem, über das ich Bescheid wissen sollte, um es richtig zu verwenden, oder ist meine Art, Navigationskomponenten zu verwenden, falsch?
Einfache Aktivität XML mit einer Ansicht:
...
<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" />
...
Navigationscode:
<?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>
Hier ist ein Github-Repo, in dem Sie einen Fehler leicht reproduzieren können: https://github.com/dmytroKarataiev/navHostBug
<fragmentin ein setzenFragmentContainerView.