I'm working on a simple app to test out JetPack Navigation in Android. My App have two activities "Activity1" and "Activity2". I'm aware that Jetpack navigation only works for SingleActivity apps but I want to see if there is any solution to my problem. App starts with "Activity1". Below is the navigation xml
<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/mobile_nav"
app:startDestination="@+id/fragmentA1">
<fragment
android:id="@+id/fragmentA1"
android:name="com.example.android.codelabs.navigation.FragmentA1"
android:label="@string/home"
tools:layout="@layout/fragment_a_one">
<action
android:id="@+id/go_to_fragmentA2"
app:destination="@+id/fragmentA2"/>
</fragment>
<fragment
android:id="@+id/fragmentA2"
android:name="com.example.android.codelabs.navigation.FragmentA2"
tools:layout="@layout/fragment_a_two">
<argument
android:name="flowStepNumber"
app:argType="integer"
android:defaultValue="1"/>
<argument
android:name="displayName"
app:argType="string"
android:defaultValue="Hello"/>
<action
android:id="@+id/go_to_fragmentA3"
app:destination="@+id/fragmentA3"/>
</fragment>
<fragment android:id="@+id/fragmentA3"
android:name="com.example.android.codelabs.navigation.FragmentA3"
android:label="fragment_third"
tools:layout="@layout/fragment_a_three">
<action android:id="@+id/go_to_activityB"
app:destination="@id/activityB"/>
</fragment>
<activity android:id="@+id/activityB"
android:name="com.example.android.codelabs.navigation.registration.ActivityB"
android:label="activity_registration_main"
tools:layout="@layout/activity_registration_main">
<argument android:name="firstName"
app:argType="string"/>
</activity>
<fragment android:id="@+id/fragmentB1"
android:name="com.example.android.codelabs.navigation.registration.FragmentB1"
android:label="fragment_step1"
tools:layout="@layout/fragment_b_one">
<argument android:name="firstName"
app:argType="string"/>
</fragment>
<fragment android:id="@+id/fragmentB2"
android:name="com.example.android.codelabs.navigation.registration.FragmentB2"
android:label="fragment_step2"
tools:layout="@layout/fragment_b_two">
<argument android:name="lastName"
app:argType="string"/>
</fragment>
Below is the code from ActivityB
val navController = findNavController(R.id.registration_navHost)
navController.setGraph(R.navigation.mobile_navigation)
navController.navigate(R.id.fragmentB1,safeArgs.toBundle())
Code to get safeArgs in ActivityB
private val safeArgs by navArgs<ActivityBArgs>()
Here are my questions. 1. How can I navigate from ActivityB(FragmentB1) to ActivityA(FragmentA2) Using jetpack Navigation. 2. Is there any way to access the backStack through any Manager Classes in android ?
Why Do I Need Two Activities? FragmentA1,FragmentA2 and FragmentA3 which are part of ActivityA shouldn't have any bottom navigation and drawer layout. Depending on answers selected in these fragments, a bottom navigation and a drawer layout are displayed in ActivityB. On Pressing back button from anywhere on ActivityB, ActivityA should come alive with FragmentA3. Also the toolBar is different for ActivityA and ActivityB
