Reputation: 41
I'm loading the contents of a database into a GridView using a CursorLoader and a ContentProvider.
The application is working but in the log is written several times "close() was never explicitly called on database.
I found some topics about this issue and the response to "close database in ContentProvider is": "A content provider is created when its hosting process is created, and remains around for as long as the process does, so there is no need to close the database".
So, whats going wrong? As the database is opened within the ContentProvider, if I close it the cursor returned will be empty, how I resolve this issue?
Upvotes: 2
Views: 1690
Reputation: 6715
That message is printed when the db is garbage collected before being closed. There is a lot of discussion about the issue here:
Closing the database in a ContentProvider
tl;dr: don't worry about it. It is, in general, actually counter-productive to close the db. Close your transactions and your cursors and let android manage the DB.
BTW, take care opening the DB in onCreate. If you open your DB using a SQLiteDatabaseHelper, the onUpdate method might be called. There isn't too much that could be worse than having your program killed by an ANR, in the middle of updating the DB.
Upvotes: 2