问题
I was trying to pass data between fragments while I was passing from upper fragment to down fragment, but I don't want to use the navigate method. It adds a new destination to the process history, but I want back to the previous fragment, restore it data and refresh the view. Is it possible to do it with NavController and popBackStack method?
回答1:
After few hours I found a strange solution. findNavController().popBackStack() cannot pass data to the previous fragment, but we can do it using the findNavController().graph.defaultArguments, set the data in one fragment, and get the data in the second one. I believe someone will find the better solution.
回答2:
I also got same problem and I have used below solution which is working, But i am not sure its correct way or not.
val navOptions = NavOptions.Builder().setPopUpTo(R.id.id_of_fragment_one, true).build()
view?.findNavController()?.navigate(R.id.id_of_fragment_one, bundleOf("id" to model), navOptions)
来源:https://stackoverflow.com/questions/52687800/android-navigation-is-it-possible-to-restore-a-bundle-from-upper-fragment-with