Search code examples
javaandroidandroid-fragmentsandroid-architecture-navigation

How to close the app on Back Pressed in Log In fragment?


I am using Navigation Components and Firebase authentication and I have two fragment [A] and [B]. where A-> Log In Fragment, B-> User List. When I successfully Logged-In from [A], I navigate to the fragment [B]. There is a Sign-Out button in [B] Fragment. when Sign Out button is pressed I signout from firebase and navigate to fragment [A]. But when I press back button then I am again navigating to fragment [B] instead of closing the app. I want to close the app if I am in Fragment [A] on back press.


Solution

  • Clear backstack and launch new top

    Learn More

    try this

    <action android:id="@+id/action_b_to_a"
                app:destination="@id/a"
                app:popUpTo="@+id/a"
                app:popUpToInclusive="true"/>