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 the Room database. Additionally, we will learn how to do long-running operations using WorkManager and some of the best practices.
In this chapter, we’re going to cover the following main topics:
- Saving...