From the course: Android Development Essential Training: 3 Navigation
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Subscribe to changes in LiveData values - Android Tutorial
From the course: Android Development Essential Training: 3 Navigation
Subscribe to changes in LiveData values
- [Instructor] Historically, Android applications may have pulled the data store or blindly requested the latest data in response to lifecycle changes. However, that's a thing of the past with the use of LiveData. LiveData allows UI components to observe data changes automatically. In our MainViewModel class, we have already created a mutable LiveData object here on line number 11. However, if you recall, we've intentionally made this object private. So only our ViewModel can update it. If we want to expose the underlying data to our activity, we'll need to create a new variable. This time it's going to be of type LiveData. That means that we won't be exposing any public methods to modify the contained value. So right underneath line number 11, we're going to create a new variable. This time we're going to call it info and it's going to be of type LiveData. It's also going to store an integer. And let's use one of…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
Handle view events with lambdas3m 35s
-
(Locked)
Explore ViewModels and LiveData3m 11s
-
(Locked)
Add a ViewModel to an Activity4m 15s
-
(Locked)
Store and publish data in a ViewModel3m 22s
-
(Locked)
Subscribe to changes in LiveData values5m 11s
-
(Locked)
✓ Challenge: Take my order2m 9s
-
(Locked)
✓ Solution: Take my order2m 29s
-
(Locked)
-
-
-