How often to run getWritableDatabase() and getReadableDatabase()?

Posted by jawonlee on Stack Overflow See other posts from Stack Overflow or by jawonlee
Published on 2010-06-17T23:25:16Z Indexed on 2010/06/17 23:33 UTC
Read the original article Hit count: 304

I'm writing a Service, a Content Provider, and one or more apps. The Service writes new data to the Content Provider's SQLite database every 5 minutes or so plus at user input, and is intended to run pretty much forever in the background. The app, when running, will display data pulled from the Content Provider, and will be refreshed whenever the Service puts more data into the Content Provider's database.

Given that the Service only inserts into the database once every five minutes, when is the right time to call SQLiteOpenHelper's getWritableDatabase() / getReadableDatabase()? Is it on the onCreate() of the Content Provider, or should I run it every time there is an insert() and close it at the end of insert()? The data being inserted every 5 minutes will contain multiple inserts.

© Stack Overflow or respective owner

Related posts about android

Related posts about database