I am trying to find a better data caching strategy in Android, especially considering using a data binding library.
The Android documentation really seems to put a lot of emphasis on using the built-in SQLite database and accessing it using content providers. However, assuming my application is extracting JSON data from the REST API, using this strategy will entail the following:
Make HTTP request --> Parse JSON --> Insert results into DB
--> Call content provider --> Build model from cursor --> Bind to view
Not only does this seem like a very roundabout way to do something relatively simple, but assuming that all this happens when the user first opens the application, the result will be waiting for a long time before something useful appears on the screen.
To speed things up, I can decide to create my model earlier and let the caching go in a separate thread, for example:
Make HTTP request --> Build model from JSON --> Bind to view
-->(NEW THREAD) --> Insert results into DB
As soon as the data is cached, the next time the application is opened, the application will take place:
Call content provider
But of course, this will add even more complexity, for example, forcing me to support the code for creating the model from two sources: JSON and cursors returned by the content provider.
Given the above, I was even more tempted to end the SQLite / ContentProvider model and instead do the following:
Make HTTP request --> Build Model and Store JSON to file --> Bind to view
But while this would significantly reduce templates, parsing (the large number of libraries available for JSON parsing), and overall complexity, it would also mean that I could not use the content providers or SQLite functionality.
, , ? , ? , ?