I have an app that has an IntentService that runs once in a while. If both of them run together the SQL statements that write to the 开发者_运维知识库database trip over each other ( datbase is locked error ) and are crashing the app.
Is there way for both the activity and the service somehow share the same database connection?
As Falmarri suggests, you can use a content provider.
Synchronize access using standard Java thread synchronization options (e.g.,
java.util.concurrent
,synchronized
keyword).The activity should not be writing to the database. The activity should be sending an
Intent
to theIntentService
and have it write to the database.
精彩评论