简体   繁体   English

是否可以使用Android导航架构组件(Android Jetpack)从“非开始”片段开始?

[英]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.

相关问题 是否可以使用 Android 导航架构组件(Android Jetpack)有条件地设置 startDestination? - Is it possible to set startDestination conditionally using Android Navigation Architecture Component(Android Jetpack)? Android导航架构组件避免了Fragment娱乐 - Android Navigation Architecture component avoid Fragment recreation 使用Android Jetpack导航组件与Android BottomAppBar - Using Android Jetpack Navigation component with Android BottomAppBar 如何使用 Android Jetpack 的导航组件禁用后退导航并删除 Fragment 上的后退箭头? - How do I disable back navigation and remove the back arrow on a Fragment, using Android Jetpack's Navigation component? 使用架构组件导航将数据从单个活动传递到起始目标片段 - Pass data from single activity to start destination fragment using Architecture Component Navigation Android Jetpack 导航:从“非导航”片段导航 - Android Jetpack Navigations: navigate from "non-navigation" fragment Android Navigation Graph 不显示开始片段 - Android Navigation Graph not displaying start fragment Android Jetpack 导航组件问题,以启动片段为根目标 - Android Jetpack Navigation component issue with splash fragment as root destination 如何使用 Android Jetpack 导航组件导航到菜单项单击的片段 - How to navigate to a Fragment on menu item click using Android Jetpack Navigation component 使用导航组件在 Android 中启动 Play Store 应用 - Start Play Store app in Android using navigation component
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM