Using LiveData

LiveData is a data holder class found in the Jetpack lifecycle-extensions library. Room is built to work with LiveData. Since you already included the lifecycle-extensions library in your app/build.gradle file in Chapter 4, you have access to the LiveData class in your project.

LiveData’s goal is to simplify passing data between different parts of your application, such as from your CrimeRepository to the fragment that needs to display the crime data. LiveData also enables passing data between threads. This makes it a perfect fit for respecting the threading rules we laid out above.

When you configure queries in your Room DAO to return LiveData, Room will automatically execute those query operations on a background ...

Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.