Reputation: 6209
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
Upvotes: 3
Views: 2885
Reputation: 302
Use Code like following to run in strict mode
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork() // or .detectAll() for all detectable problems
.penaltyLog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.penaltyLog()
.penaltyDeath()
.build());
This starts producing on closable things etc. Hence helps in debugging where the error arose from.
Source : https://developer.android.com/reference/android/os/StrictMode.html
Upvotes: 0
Reputation: 755
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.
Upvotes: 5