views:

37

answers:

1

Hi. I have android application and service that runs in separate process. Application and service read and write to same database (and same table). What is the best way to work with database? How to prevent locks?

A: 

I have android application and service that runs in separate process.

This is a bad idea on Android in most cases. Why do you have them in separate processes?

What is the best way to work with database? How to prevent locks?

Put them both in the same process. If needed, use the synchronized keyword or concurrency-control classes in java.util.concurrent to coordinate access to the database.

CommonsWare