Intro To Android (Workbook 2)

Lab: Persistence

We could serialize our GSON and store in shared preferences, but we're going to store and query a DB instead.

Steps

  1. Start with the Android tutorial to implement your DB contract.
  2. Continuing with the tutorial, create your DB helper class, database, and tables.
  3. Store your downloaded data in your newly minted DB using ContentValues.
  4. Create an AsyncTaskLoader to load your data from the DB. The documentation gives a good example.
  5. Implement LoaderManager.LoaderCallbacks and display your data after fetched.
  6. Revisit your logic for when you are fetching data from the network.
  7. Store in the shared preferences the fetched date and display in the log when the data was last fetched.
    • Normally there'd be a last updated date in the JSON that you can compare your data set against.
  8. Store the last tab the user was viewing in the shared preferences and show when restoring the view.

Note: Start small with one fragment/set of data and make sure that works before moving on to making both work.


Note: Remember to test early and test often.

Resources

SQLite DB Storage