Sign in Go Pro

Storing Data in Android with Room


This lesson is for PRO members.

Upgrade today to get access to all the PRO lessons.

Unlock this lesson

Up next



In this lesson, we describe what LiveData is and how it can simplify reading values from a Room database.

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 SELECT query.

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 LiveData
  • How to update a SELECT query to return an observable list of tasks
  • How to observe LiveData in order to be notified of any changes
  • LiveData ensures data is read on a background thread, but your observing code is notified on the main thread





There are no comments on this lesson, start the conversation below ...

You need to go PRO to post comments.

Lessons in Storing Data in Android with Room