We can initialize the ViewModel class using
private val viewModel: CharactersViewModel by viewModels()
or
viewModel = ViewModelProvider(this).get(CharactersViewModel::class.java)
Herer CharactersViewModel is our ViewModel class. My question is when to use which?
Do both contain the same purpose? I have read the android official documentation of ViewModel.The documentation says by viewModels() Kotlin property delegate. But unfortunately failed to understand it. Can anyone help me understand this?