I would like to follow this nice usability pattern, where app stores data offline for faster response and updates it when it gets new data online.
And I use Loaders
with LoaderManager
.
Now, what is the correct approach to implement the aforementioned approach with Loaders
?
Currently I use two approaches, which have their downsides and, generally, are not very elegant.
- Storing the data in the application context instead of SQLite
- Two separate
AsyncTaskLoaders
-offlineLoader
andonlineLoader
. The first fetches the data from SQLite database and shows it immediately if it's there and the second one loads the data from external server, writes it to database (for the offlineLoader) and replaces the offline data
What I would really like to have is:
A single Loader which fetches the data offline and returns it to LoaderManager, but continues to work afterwards and return the fresh online data when it's ready. So it should return twice - is it even possible?