0

I have a fragment A that is used to host a nav graph but I would like to set the graph programmatically when having get the api result by this code findNavController().setGraph(R.navigation.nav_graph). Also in the fragment A I have create a viewModel B instance and assign some api data to it so I can invoke it as a shared viewModel in a fragment in my nav_graph. This is my code to retrieve the viewModel B in my child fragment (in the nav_graph)

private val sharedValuationViewModel by viewModel<SharedValuationViewModel>(owner = {
        ViewModelOwner.from(requireParentFragment().requireParentFragment().viewModelStore) }) // Koin syntax to get shared viewModel

The problem is that the viewModel I got is not the same the viewModel in fragment A (I have check their address on RAM are different). Any suggestions to solve this case? Really appreciate for your help.

Navigation version 2.3.5

Koin version 2.2.1

0 Answers0