Navigate between different graphs with Navigation components
You don't need to define a second activity, simply add a second navigation graph to your nav_graph.xml
file. Something like:
<?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/loginFragment">
<fragment
android:id="@+id/loginFragment"
android:name="com.mycompany.loginFragment"
tools:layout="@layout/fragment_login"
android:label="Login" >
<action
android:id="@+id/action_loginFragment_to_new_graph"
app:destination="@id/new_graph" />
</fragment>
<include app:graph="@navigation/new_graph" />
</navigation>
Then, with your navController
, navigate the action:
navController.navigate(R.id.action_loginFragment_to_new_graph)