Skip to content

Instantly share code, notes, and snippets.

@ErikMedina
Last active December 25, 2021 12:12
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ErikMedina/72f97472659641903bf8d4aa56d3dddf to your computer and use it in GitHub Desktop.
Backwards destinations
<?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_graph"
app:startDestination="@id/homeFragment">
<fragment
android:id="@+id/homeFragment"
android:name="com.erikmedina.navigationcomponent.HomeFragment"
android:label="fragment_first"
tools:layout="@layout/fragment_home">
<!-- Actions to navigate straight to a destination -->
<action
android:id="@+id/action_homeFragment_to_firstFragment"
app:destination="@id/firstFragment" />
<action
android:id="@+id/action_homeFragment_to_secondFragment"
app:destination="@id/secondFragment" />
<action
android:id="@+id/action_homeFragment_to_thirdFragment"
app:destination="@id/thirdFragment" />
</fragment>
<fragment
android:id="@+id/firstFragment"
android:name="com.erikmedina.navigationcomponent.FirstFragment"
tools:layout="@layout/fragment_first">
<action
android:id="@+id/action_firstFragment_to_secondFragment"
app:destination="@id/secondFragment" />
<!-- Back navigation from FirstFragment to HomeFragment -->
<action
android:id="@+id/action_firstFragment_to_homeFragment"
app:destination="@id/homeFragment" />
</fragment>
<fragment
android:id="@+id/secondFragment"
android:name="com.erikmedina.navigationcomponent.SecondFragment"
tools:layout="@layout/fragment_second">
<action
android:id="@+id/action_secondFragment_to_thirdFragment"
app:destination="@id/thirdFragment" />
<!-- Back navigation from SecondFragment to FirstFragment -->
<action
android:id="@+id/action_secondFragment_to_firstFragment"
app:destination="@id/firstFragment" />
</fragment>
<fragment
android:id="@+id/thirdFragment"
android:name="com.erikmedina.navigationcomponent.ThirdFragment"
tools:layout="@layout/fragment_third">
<!-- Back navigation from ThirdFragment to SecondFragment -->
<action
android:id="@+id/action_thirdFragment_to_secondFragment"
app:destination="@id/secondFragment" />
</fragment>
</navigation>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment