如何从Android Navigation Controller中的通知导航Fragment

时间:2019-01-27 10:40:52

标签: android kotlin androidx android-architecture-navigation

我应该创建一个导致MainActivity的Intent,然后在其中导航功能。还是有其他方法?

1 个答案:

答案 0 :(得分:0)

从通知中将挂起的意图写入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)