ViewModel class is designed to store and manage UI-related data. They are responsible to prepare & provide data for UI and automatically allow data to survive configuration change.
In this lesson, we will look at the problems of managing data in the
Fragment and then use
ViewModel to solve those problems. We will also dive deep into how ViewModels internally work. You'll learn to solve the "God Activity" problem and start to keep only UI logic in the
cloning the repository the Observer does not get updated, it indicates even not zero from the beginning but the LiveData object in the screen. If I breakpoint the increment method in the View Model, is updated without problems with successive int values (1,2 etc)
counter.value = counter.value?.inc()
EDIT=Actually the activity in the GIT is different by the one in the text, there is any observe method subscription of LiveData in the original
I do not understand how come you call directly the xml attribute id as an object ex count.
how is possible that?
There is a little difference between the Activity on Git and in the video to keep it simple to explain in the video.
The magic of directly calling the xml attribute id is done using
Kotlin Android Extension plugin. Check out this lesson for more information: