Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do not include fragment in backstack using Android Navigation Component

I'm working on an app where users can create events. I would like to make it so that the after they create the event the back button would not take them to the creation flow, but to the screen before the creation flow. Something like:

Main Screen -> Creation Flow -> Event Summary

Then if they press the back button I want it to go

Event Summary (back button) Main Screen

I've gotten close with:

<fragment
    android:id="@+id/createMeetFragment"
    android:name=".CreateMeetFragment"
    android:label="CreateMeetFragment" >
    <action
        android:id="@+id/action_createMeetFragment_to_meet_detail_graph"
        app:destination="@id/meet_detail_graph"
        app:popUpTo="@+id/mainFragment" />
</fragment>

This works well enough in that it will pop-up to the Main screen. I haven't found much documentation for these pop behavior options just this.

The issue I have with this solution is that as I understand it, it will pop until we get to the MainScreen, regardless of how the user got to the event creation. I'd prefer a solution that just pops to the screen before the creation flow, allowing for multiple entry points to the creation flow.

like image 747
Ryan C Avatar asked Mar 06 '23 12:03

Ryan C


1 Answers

I'd prefer a solution that just pops to the screen before the creation flow, allowing for multiple entry points to the creation flow.

You should not pop up to the main screen but to the first screen of creation flow inclusively.

<fragment
    android:id="@+id/createMeetFragment"
    android:name=".CreateMeetFragment"
    android:label="CreateMeetFragment" >
    <action
        android:id="@+id/action_createMeetFragment_to_meet_detail_graph"
        app:destination="@id/meet_detail_graph"
        app:popUpTo="@+id/firstCreateFlowFragment" 
        app:popUpToInclusive="true" />
</fragment>
like image 169
jaychang0917 Avatar answered Mar 10 '23 11:03

jaychang0917