I have been trying to run my application in StrictMode to check for any hidden problem that may have sneaked. One issue I ran across is what seems to be a false positive of Leaked DatabaseConections when using ContentResolver.
After some experiments got the issue simplified to the following 2 lines of code:
Cursor c = context.getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, cols, null, null, MediaStore.Video.Media.DEFAULT_SORT_ORDER);
c.close()
The 2 lines above generate the following StrictMode violation:
ERROR/StrictMode(26219): Releasing cursor in a finalizer. Please ensure that you explicitly call close() on your cursor:
ERROR/StrictMode(26219): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
ERROR/StrictMode(26219):
at android.database.CursorWindow.<init>(CursorWindow.java:62)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:403)
at android.content.ContentResolver.query(ContentResolver.java:302)
I am assuming that this is something specific to the fact that the Cursor was returned by a contentProvider (so it is not a direct SQLite cursor).
Does anyone have any insight if this is indeed a false positive or there is really a leaky cursor.