我在主 Activity 中有底部导航,并且有一个数据MainActivity
,我想将它传递给 HostFragments 我正在使用 NavigationExtensions 表单谷歌 NavigationAndvancedSample 示例这里是我在 MainActivity 中使用的扩展功能,但你知道我如何传递最好的数据将意图包含的数据传递给 HostFragments 的方法?你可以看到我有 fragmentTag 和 navigationHostFragment
fun BottomNavigationView.setupWithNavController(navGraphIds: List<Int>,
fragmentManager: FragmentManager,containerId: Int,intent: Intent)
private fun obtainNavHostFragment(
fragmentManager: FragmentManager,
fragmentTag: String,
navGraphId: Int,
containerId: Int
): NavHostFragment {
// If the Nav Host fragment exists, return it
val existingFragment = fragmentManager.findFragmentByTag(fragmentTag) as NavHostFragment?
existingFragment?.let { return it }
// Otherwise, create it and return it.
val navHostFragment = NavHostFragment.create(navGraphId)
fragmentManager.beginTransaction()
.add(containerId, navHostFragment, fragmentTag)
.commitNow()
return navHostFragment
}````