Home:ALL Converter>Android Navigation component navigation issue

Android Navigation component navigation issue

Ask Time:2022-08-02T18:25:44         Author:Code Learner.

Json Formatter

I am using the navigation component to navigate between fragments. this is the flow splash -> login -> Register

login -> Home

  1. here i am navigating to login from splash and removing splash instance by using popUpTo ="@id/splash", popUpToInclusive ="true". -- no issue successfully removing an instance of splash and when back click app is closing(as I don't want splash screen again when back press.).

  2. navigation from login to home without any issue(removing login instance after the successful transaction as I don't need to back to login.).

  3. here I have one issue I navigated to Register from login without any popUpTo and PopUpToInclusive. and navigate back to login without any issue. and I tried to navigate to the home screen here starting destination should be loginScreen but it's SplashScreen, so navigation failed unable to navigate to the home screen (App is crashing with the error "no starting destination was found")

    java.lang.IllegalArgumentException: Navigation action/destination com.self.user:id/action_loginFragment_to_navigation_homeFragment cannot be found from the current destination NavGraph(com.self.user:id/mobile_navigation) startDestination={Destination(com.self.user:id/splashFragment) label=SplashFragment class=com.self.user.ui.fragment.SplashFragment

<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_navigation"
    android:theme="@style/Theme.AppCompat.DayNight.NoActionBar"
    tools:ignore="UnusedNavigation"
    app:startDestination="@id/splashFragment">

    <fragment
        android:id="@+id/splashFragment"
        android:name="com.self.user.ui.fragment.SplashFragment"
        android:label="SplashFragment"
        tools:layout="@layout/splash_fragment">

        <action
            android:id="@+id/action_splashFragment_to_loginFragment"
            app:destination="@id/loginFragment"
            app:popUpTo="@id/splashFragment"
            app:popUpToInclusive="true"/>
    </fragment>

    <fragment
        android:id="@+id/loginFragment"
        android:name="com.self.user.ui.fragment.LoginFragment"
        android:label="LoginFragment"
        tools:layout="@layout/login_fragment">
        <action
            android:id="@+id/action_loginFragment_to_navigation_homeFragment"
            app:destination="@id/navigation_homeFragment"
            app:popUpTo="@id/loginFragment"
            app:popUpToInclusive="true"/>
        <action
            android:id="@+id/action_loginFragment_to_registerFragment"
            app:destination="@id/registerFragment" />
    </fragment>
    <fragment
        android:id="@+id/registerFragment"
        android:name="com.self.user.ui.fragment.RegisterFragment"
        android:label="RegisterFragment"
        tools:layout="@layout/register_fragment">

        <action
            android:id="@+id/action_registerFragment_to_navigation_homeFragment"
            app:destination="@id/navigation_homeFragment"
            app:popUpTo="@id/loginFragment"
            app:popUpToInclusive="true" />
    </fragment>

    <fragment
        android:id="@+id/navigation_homeFragment"
        android:name="com.self.user.ui.fragment.HomeFragment"
        android:label="HomeFragment"
        tools:layout="@layout/home_fragment"/>
    <fragment
        android:id="@+id/navigation_profileFragment"
        android:name="com.self.user.ui.fragment.ProfileFragment"
        android:label="ProfileFragment"
        tools:layout="@layout/profile_fragment"/>
</navigation>```



   

Author:Code Learner.,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/73205940/android-navigation-component-navigation-issue
yy