DEV Community

Discussion on: Android ViewModel Example

Collapse
 
golex12 profile image
golex12

Hello!

private lateinit var viewModel: MainViewModel = ViewModelProviders.of(this).get(MainViewModel::class.java)

ViewModelProviders' is deprecated!!!
developer.android.com/reference/ko...

You need to use something like this:
Isn't it?
private val viewModel: MainViewModel by lazy {
ViewModelProvider(this).get(MainViewModel::class.java)
}