so I have the following navigation graph:
Fragment A (start) --> Fragment B
So for some situations (firebase notifications), I need to start Fragment B
directly, passing data from the notifications. Now, this works. However, when I press the back button, it results in a crash. Is it because the leading fragment ( Fragment A
) is not in the stack? If so, is there a way to properly handle this. Basically, I need the backPressed action to launch the start Fragment ( Fragment A
) in a situation where Fragment B
is launched directly without passing through Fragment A
.
Below is a snippet of my graph:
<fragment
android:id="@+id/homeFragment"
android:name="dita.dev.myportal.ui.home.HomeFragment"
android:label="Home"
tools:layout="@layout/fragment_home">
<action
android:id="@+id/action_homeFragment_to_messageDetailFragment"
app:destination="@id/messageDetailFragment"
app:exitAnim="@anim/fade_out_animation" />
</fragment>
<fragment
android:id="@+id/messageDetailFragment"
android:name="dita.dev.myportal.ui.messages.details.MessageDetailFragment"
android:label="Message"
tools:layout="@layout/fragment_message_detail">
<argument
android:name="title"
app:argType="string" />
<argument
android:name="message"
app:argType="string" />
</fragment>
I hope the link helps. https://developer.android.com/guide/navigation/navigation-deep-link
Deep links allow for synthetic back-stacks. Quoted from the website, "This means that when a user presses the Back button from a deep link destination, they navigate back up the navigation stack just as though they entered your app from its entry point." Maybe trying to create a deep link for Fragment B will work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.