如何从 Android 导航控制器中的通知导航片段

How to navigate Fragment from notification in Android Navigation Controller

我是否应该制作一个指向 MainActivity 的 Intent,然后在那里导航功能。或者有其他方法吗?

从通知将待定意图写入 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)