Does reading of a Android Cursor go all the way to the database?
I've got a kind of heavy Android application and want to make sure not never ANR it.
I've moved my database queries away from the UI thread (to AsyncTasks), but I still read from the cursor in the ui thread since I s开发者_开发技巧uppose the returned cursor is stored somewhere in memory, i.e. the actual reading of it does not go the entire way to the database. Is that correct or do i really need to move all reads of the cursor to non UI threads as well?
To be more specific:
Does for example http://developer.android.com/reference/android/database/Cursor.html#getInt(int) read from memeory, or does it aquire some kind of read lock from the actual SQLite database.
I guess the Cursor implementation in my case is an SQLiteCursor since the ContentProvider is implemented using an SQLite database.
When you call query()
or rawQuery()
on a SQLiteDatabase
, a Cursor
is returned immediately, because the actual query itself is delayed until you start using data. Any call that manipulates the Cursor
or needs data that implies that the query is executed (e.g., getCount()
) will actually execute the query. Hence, it is best to "touch" the Cursor
in doInBackground()
while you are on the background thread.
From that point forward, though, the entire result set is in memory, for result sets under 1MB.
精彩评论