Does Android cursor look at all database paths?

I have a kind of heavy Android app and you want it to never be ANR.

I moved my database queries from the user interface thread (in AsyncTasks), but I am still reading the cursor in the ui thread, since I believe that the returned cursor is stored somewhere in memory, that is, its actual reading does not go all the way to the database. Is this correct or do I really need to move all cursor reads to uninitialized threads?

More specific:

Is there, for example, http://developer.android.com/reference/android/database/Cursor.html#getInt(int ) read from memeory, or does it use some kind of read lock from a real SQLite database.

I assume that the Cursor implementation in my case is SQLiteCursor, since the ContentProvider is implemented using the SQLite database.

+3
source share
1 answer

When you call query()or rawQuery()on SQLiteDatabase, it immediately returns Cursorbecause the actual request itself is delayed until you start using the data. Any call that manages data Cursoror needs data that involves executing a request (for example getCount()) will actually execute the request. Therefore, it’s best to “touch” Cursorin doInBackground()while you are in the background thread.

, , , 1 .

+10

Source: https://habr.com/ru/post/1780613/


All Articles