【问题标题】:How to navigate Fragment from notification in Android Navigation Controller如何从 Android 导航控制器中的通知导航片段
【发布时间】:2019-01-27 10:40:51
【问题描述】:

我是否应该创建一个通向 MainActivity 的 Intent,然后在那里导航功能。还是有其他方法?

【问题讨论】:

  • 你找到解决办法了吗?
  • 是的。首先使用操作和创建指向 MainActivity 的待处理意图点。在主要活动中使用 navController 上的 addOnDestinationChangedListener,检查通知中的 action == 是否直接导航到视图。
  • @p.mathew13 你有更好的解决方案吗?

标签: android kotlin androidx android-architecture-navigation


【解决方案1】:

从通知写入待处理意图到 MainActivity 并从那里使用其 id 导航到特定片段

val bundle = intent.extras
findNavController(R.id.homeHostFragment)
            .navigate(R.id.notificationsFragment, bundle, null)

    //here homeHostFragment is the id for fragment in xml for which we set the nav graph
    val bundle = intent.extras
    val navHostFragment = homeHostFragment as NavHostFragment
    navHostFragment.navController.navigate(R.id.notificationsFragment,bundle)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-06
    • 1970-01-01
    • 2020-10-02
    • 2023-02-14
    • 1970-01-01
    相关资源
    最近更新 更多