Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LiveData features -
- 1.Synchronous
- 2.Used for notifying
- 3.No memory leaks
- 4.No crashes
- 5.No manual lifecycle handling
- 6.It acts as a data holder.
- Implementation steps -
- 1.Create LiveData instance to hold certain type of data.Usually done within ViewModel class.
- 2.Create Observer object that defines onChanged(), which controls what will happen when LiveData object held data changes.
- Usually Observer object is created in Activity/Fragment.
- 3.Attach Observer object to LiveData object using observe() method. observe() takes a LifecycleOwner object.This
- subscribes the Observer object to the LiveData object so that it will be notified of changes.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement