[英]Is it possible to start with a “non-start” fragment using Android Navigation Architecture Component(Android Jetpack)?
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. 所以对于某些情况(firebase通知),我需要直接启动
Fragment B
,从通知中传递数据。 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? 是因为前导片段(
Fragment A
)不在堆栈中吗? 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
. 基本上,我需要backPressed动作来启动
Fragment B
直接启动而不通过Fragment A
的情况下启动片段( 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
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.
也许尝试为Fragment B创建一个深层链接会起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.