Tiago Nunes
02/24/2021, 6:08 PM@HiltViewModel
class SomeViewModel @Inject constructor(
savedStateHandle: SavedStateHandle,
): ViewModel() {
val argument: Argument =
savedStateHandle[ParentFragmentArgs::argument.name]!!
}
However, this does not work with SharedViewModel (
private val viewModel: SomeSharedViewModel by activityViewModels()
)
I think I understand why. This ViewModel isn't scoped to the Fragment, but to the Activity, so it probably gets the savedState of the Activity instead of the Fragment's (right?)Ian Lake
02/24/2021, 6:16 PMprivate val viewModel: SomeSharedViewModel by viewModels({ requireParentFragment() })
Tiago Nunes
02/24/2021, 6:21 PM