Is it possible to mock the sqlite3 cursor in Android if there is no db or table?

I am using ContentProvider to cache the results of a web service request. This is an HTTP request, and the response content is XML. Most of the data is cached, so I just query the database, if not found, the request from webservice, inserts into the database and queries the database. So the answer is always the cursor from SQLiteDatabaseHelper.

I have one result set that is not stored in the database, and since it is a 100% transient, but I would like to present its appearance from the DB cursor. Is there an easy way to do this? For example, if I could project it onto a cursor using cursor.setValue ("string", objectValue) or some other existing implementation.

If not, I will either bypass DB for this content result, or add it to a trivial table that is constantly reused.

+6
android android-contentprovider mocking sqlite3
source share
1 answer

Depending on how you use it, it may not be too difficult to write your own cursor class. For convenience, derive your class from the AbstractCursor class, which takes care of a lot for you.

You can also use MatrixCursor .

+10
source share

All Articles