1 min readSep 7, 2019
Short and sweet! I just needed to remove the create
function’s Class argument ignore null value safety ?
and the ViewModelFactory is working.
class CustomViewModelFactory(private val repository: SomeRepository)
: ViewModelProvider.NewInstanceFactory() {
override fun <T : ViewModel?> create(modelClass: Class<T>): T = SomeViewModel(repository) as T
}
Update 2/24/20
I’ve used the latest Lifecycle 2.2.0 release in order to add both custom parameters and Saved State to the ViewModel component.