Offline Support
Apply what you’ve learned about a Repository pattern to build offline support in this lesson.
We'll cover the following
Usage of Blog Repository
Now that we have all the necessary pieces to implement offline support, we can finally use them in the MainActivity
.
Start by creating a BlogRepository
object in the onCreate
method (1).
In the OnRefreshListener
, we are going to call the loadDataFromNetwork
method (2).
At the very end of the onCreate
method, when everything is initialized, we can load data from the database (3) and launch loading data from the internet (4). Because loading data from the database is very fast and loading data from the internet is slow, we will see cached data until the data from the internet is loaded.
Get hands-on with 1400+ tech skills courses.