In this lesson, we describe what
LiveData is and how it can simplify reading values from a
LiveData is an observable data holder class.
LiveData provides a way to run queries asynchronously on a background thread and can notify you automatically whenever a change is made to your database.
We'll demonstrate the power of
LiveData by modifying our
SELECT query to return
LiveData which will always contain the most up-to-date task list from the database.
We'll remove the need to manually refresh the task list; instead, we'll observe the
LiveData returned by our
This is moving towards a more reactive architecture, where we have the database as a single source of truth and the UI updating automatically whenever changes occur in the database. This reduces the possibility of the UI and database falling out of sync with each other and reduces the amount of code we need to write.
Summary of Content:
- Features and advantages of
- How to update a SELECT query to return an observable list of tasks
- How to observe
LiveDatain order to be notified of any changes
LiveDataensures data is read on a background thread, but your observing code is notified on the main thread