I'm writing a Service, a Content Provider, and multiple 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.