I’m working on an application that allows users to send and receive messages. The messages are stored in a database on a server. I would like to display the messages in a ListView, similar to an email inbox. Here is my planned implementation:
- On starting the message activity, populate the list using a
CursorLoaderand anSQLitecache of messages stored on the device (e.g. from the last week) - Download new messages from the server and add them to the
SQLitedatabase, and update theCursor - Download older messages as the user scrolls (but don’t store them), and make sure there are enough messages loaded that scrolling doesn’t lag.
Here are my questions:
- Does this seem like a good strategy in general?
- When I download and store new messages, is there a way to update the
Cursorso its data is synced with theSQLitedatabase? - When I download old messages, is there a way I can add them to the
Cursorso that I can have aCursorAdapterhandling theListView?
Yes this sounds like a good strategy. The key point here is to wrap the two data sources (SQLite and Server Data) into single source and to fetch data from it.