SavedState integration with Koin viewmodels
See original GitHub issueIs your feature request related to a problem? Please describe. Android introduced SavedState support in their ViewModels. Now we do not need to access onSaveInstanceState overrides from the Fragment / Activity. However Koin doesn’t agree with this even though we do have a technique for sending custom parameters in the viewmodels.
To access the saved state in the ViewModels , this will be the signature of the ViewModel
class SavedStateViewModel(val savedStateHandle: SavedStateHandle):ViewModel()
{
}
To create it without Koin , we use a ViewModelProvider
ViewModelProviders.of(this,SavedStateVMFactory(this)).get(SavedStateViewModel::class.java)
Describe the solution you’d like
Describe alternatives you’ve considered I have tried injecting the SavedStateHandle by going through the following.
val viewModels = module {
viewModel { (ssh:SavedStateHandle)-> SavedStateViewModel(ssh) }
}
This wont work because we need to access a different factory called SavedStateVMFactory in order for the SavedStateHandle to be sent into the ViewModel object
Is there anyway to achieve SavedStateHandles inside our viewmodels via Koin
https://developer.android.com/topic/libraries/architecture/viewmodel-savedstate#kotlin
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (3 by maintainers)
It seems to be ready: https://doc.insert-koin.io/#/koin-android/viewmodel?id=viewmodel-and-state-bundle
Having the same problem as @caiodev . I suspect that since my activity is the first, when Android kills it, it kills the whole app, including the handle. Might be an SavedStateHandle problem or Koin, I’m not sure at this point.