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.

See: Optimizing Android ViewModel with Lifecycle 2.2.0 🤖🧰

Creator of Coinverse - The 1st Crypto News Audiocast App @ bit.ly/play-coin

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store