【发布时间】:2021-07-15 07:09:24
【问题描述】:
我有两个片段。 SecondFragment 和 ThirdFragment。实际上,我使用导航组件在片段之间传递值。像这样:
SecondFragment:
val action = SecondFragmentDirections.action_secondFragment_to_thirdFragment().setValue(1)
Navigation.findNavController(it).navigate(action)
这是我从 ThirdFragment 读取值的方式:
arguments?.let {
val args = ThirdFragmentArgs.fromBundle(it)
thirdTextView.text = args.value.toString()
}
一切正常。现在我的堆栈是这样的:
ThirdFragment
SecondFragment
有没有任何选项可以将值从打开的 ThirdFragment 传递到前一个 SecondFragment 与新的导航组件? (当 ThirdFragment 完成时)
我知道 onActivityResult,但如果 Nav.Component 提供的解决方案比我想要的更好。
谢谢!
【问题讨论】:
标签: android android-fragments android-architecture-navigation