I am new to the mvvm pattern. I created a ViewModel for the main activity. Now I want to get an instance of the ViewModel in the main activity.
Most Tutorials and answe
Use val viewModel by viewModels() in Activities and val viewModel by activityViewModels() in fragment to obtain the same viewmodel from the activity (so sharing the viewmodel).
val viewModel by viewModels()
val viewModel by activityViewModels()
This is part of androidx now
androidx