When should I call close() on SQLiteOpenHelper used by ContentProvider

cmoaciopm picture cmoaciopm · Dec 16, 2011 · Viewed 12.8k times · Source

In my android app, I use SQLiteOpenHelper to implements ContentProvider. Query, add, delete operations are all through ContentProvider.

But in one of my android phone(htc g13), I found *.db-wal file in directory /data/data/[package name]/databases. And the file size increate very fast when operating with ContentProvider. It occupied user RAM space too much.

It is recommended to close the SQLiteOpenHelper to solve my problem (it is useful) in post enter link description here.

But I want to find a "place" to add the "close()" method since I am not using SQLiteOpenHelper directly (using through ContentProvider). query() method in ContentProvider must return a Cursor, and SQLiteDatabse should stay in open state.

I'm confused, what show I do now to keep *.db-wal gone and use ContentProvider normally?

Answer

Tarun picture Tarun · Aug 8, 2013

Android framework engineer defer to this view that you need to close the DB.

As per Dianne Hackborn(Android Framework Engineer) in this thread:

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 -- it will get closed as part of the kernel cleaning up the process's resources when the process is killed.