Search code examples
databasecursorandroid-contentprovider

Get Cursor finalized without prior close() message even if I use ContentProvider


I use ContentProvider but sometimes I get the message written in the title. What is the reason? I read that this message would appear if I closed a database before closing a cursor. I also read that I shouldn't take care of closing the cursor if I use ContentProvider

Link: Closing the database in a ContentProvider


Solution

  • It's true that you don't have to close the database when using ContentProvider, but this doesn't apply for cursors. You must be using getContentResolver().query() which returns a cursor. Eventually you will have to close that returned cursor with .close(), otherwise you'll get that nasty message.