Skip to content

Instantly share code, notes, and snippets.

@ErikMedina
Last active Dec 25, 2021
Embed
What would you like to do?
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