tankistorep
08/10/2023, 10:27 AMSavedStateHandle
- say I have a ViewModel that needs a class that needs `SavedStateHandle`:
@Inject
class MyViewModel(private val test: SomeTestClass): ViewModel()
@Inject
class SomeTestClass(private val savedStateHandle: SavedStateHandle) {...}
And I have my own view model factory:
@Inject
class ViewModelFactory(
val myViewModel: (SavedStateHandle) -> MyViewModel
): ViewModelProvider.Factory {
override fun <T : ViewModel> create(
modelClass: Class<T>,
extras: CreationExtras
): T {
val savedStateHandle = extras.createSavedStateHandle()
return when (modelClass) {
MyViewModel::class.java -> myViewModel(savedStateHandle) as T
...
}
}
}
Is there a way to get the SavedStateHandle
to be automatically passed down to SomeTestClass
without me needing to create an instance of the class in the factory?stantronic
08/10/2023, 2:37 PMstantronic
08/10/2023, 2:37 PMstantronic
08/10/2023, 2:39 PMtankistorep
08/10/2023, 2:41 PMstantronic
08/10/2023, 2:43 PMtankistorep
08/10/2023, 2:44 PM