Search code examples
androidandroid-architecture-componentsandroid-viewmodel

whats the difference between viewModel and viewModels class


In this code I am creating a reference to the GameViewModel class which extends the ViewModel class I know why we are delegating the responsibility to viewModels() but I want to know what actually is this viewModels and how it is different from ViewModel

private val viewModel: GameViewModel by viewModels()

Solution

  • You compare kotlin delegate function( by viewModels()) and ViewModel class together, open sources i think that will help you better understand.