Enabling offline usage by implementing Room
We want to locally cache all the restaurants that we receive from our Firebase database. Since this content is structured, we want to use Room to help us with this task.
Essentially, we are trying to save the restaurants when the user is browsing our Restaurants app while online. Then, we will reuse them when the user browses the app while being offline:
When online, we retrieve the restaurants from our web API. Before displaying them to the user, first, we will cache them to our Room database. If offline, we will retrieve the restaurants from the Room database and then display them to the user.
Essentially, we are creating two sources of truth for our app:
- The remote API for when the user is online
- The local Room database for when the user is offline
In the next section, we will discuss why this approach...