Search code examples
androidandroid-sqliteandroid-contentproviderandroid-cursorloader

Android using a cursor on UI thread


I am wondering when or if its ok to use a cursor to get data from a sqlite database on the ui thread. Basically I use a cursorloader to get a cursor. And then I want to do something with that cursor. Is it ok to do something with the cursor from the main ui thread? Really I just need to read one row from the cursor.


Solution

  • Retrieving a row from a Cursor is not an expensive operation... querying the data from the database, on the other hand, could be time-consuming depending on the amount of data you are requesting and/or the complexity of the query. CursorLoaders query for Cursors asynchronously so your approach is fine.