开发者

How can an activty and a service write to DB at the same time?

开发者 https://www.devze.com 2023-02-08 16:13 出处:网络
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

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?


  1. As Falmarri suggests, you can use a content provider.

  2. Synchronize access using standard Java thread synchronization options (e.g., java.util.concurrent, synchronized keyword).

  3. The activity should not be writing to the database. The activity should be sending an Intent to the IntentService and have it write to the database.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号