0

I have a navgraph with two activities and multiple fragments within them.

Here is my graph

<?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"
    android:id="@+id/job_nav_graph"
    app:startDestination="@id/signInFragment">
    <fragment
        android:id="@+id/signInFragment"
        android:name="com.plcoding.posterpalfeature.ui.fragments.SignUpFragment"
        android:label="Sign In" >
        <action
            android:id="@+id/action_signInFragment_to_loginFragment"
            app:destination="@id/loginFragment" />
    </fragment>
    <fragment
        android:id="@+id/settingsFragment"
        android:name="com.plcoding.posterpalfeature.ui.fragments.SettingsFragment"
        android:label="Setting"/>
    <action android:id="@+id/action_global_settingsFragment" app:destination="@id/settingsFragment"/>

    <include app:graph="@navigation/job_navigation" />
    <fragment
        android:id="@+id/loginFragment"
        android:name="com.plcoding.posterpalfeature.ui.fragments.LoginFragment"
        android:label="LoginFragment">
        <action
            android:id="@+id/action_loginFragment_to_mainActivity"
            app:destination="@id/mainActivity" />
    </fragment>

    <activity
        android:id="@+id/signUpLogin"
        android:name="com.plcoding.posterpalfeature.ui.activity.SignUpLogin"
        android:label="SignUpLogin" />
    <activity
        android:id="@+id/mainActivity"
        android:name="com.plcoding.posterpalfeature.ui.activity.MainActivity"
        android:label="MainActivity" />
</navigation>

The application launches into the SignUpLogin activity. Here is the XML layout

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/fragment_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
<androidx.fragment.app.FragmentContainerView
        android:id="@+id/nav_host_fragment"
      android:name="androidx.navigation.fragment.NavHostFragment"
        android:tag="my_fragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:defaultNavHost="true"
        app:navGraph="@navigation/main_nav_graph"
        />

</FrameLayout>

When I use this action

 <action
            android:id="@+id/action_loginFragment_to_mainActivity"
            app:destination="@id/mainActivity" />

It navigates to MainActivity but the SignUnFragment is shown instead.

What am I missing? There are no connections I can make between the MainActivity and and the associated fragments of that flow.

user1743524
  • 655
  • 1
  • 7
  • 14

0 Answers0