8

Persisting Data Locally and Doing Background Work

To provide better user experiences, we must ensure that apps don’t fetch data every time the user opens the app. At times, the user can be in areas that do not have internet access, and this can be very frustrating when the user can’t use your app in such situations. For such scenarios, we have to store data locally. We also have to store and update the data in an efficient way that doesn’t drain the device’s battery or block the user from doing other things on the app. In this chapter, we will be exploring how to do so for our apps.

In this chapter, we will learn how to save data to a local database, Room, which is part of the Jetpack libraries. We will be able to save items and read from ...

Get Mastering Kotlin for Android 14 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.