Database handling with 2 processes

前端 未结 4 1856
甜味超标
甜味超标 2021-01-01 12:32

I have a an application that has 2 parts.

  • A service which creates content.
  • An application that uses the content

Each of these run as di

相关标签:
4条回答
  • 2021-01-01 13:04

    The following is a great article on how locking works with SQLite on Android and what things to be aware of: http://kagii.squarespace.com/journal/2010/9/10/android-sqlite-locking.html

    I would think you'll find some answers there :)

    0 讨论(0)
  • close the connection after each operation

    catch the database locked error and try to reconnect after 50ms

    or let the service handle the database and the activity ask the service for data

    may be there is isDatabaseInUseMethod ?

    0 讨论(0)
  • 2021-01-01 13:11

    Using a content provider is one option. Another is to take a look at Berkeley DB. The BDB SQL API is SQLite compatible and the BDB lock manager allows multiple threads and/or processes to read/write to the database concurrently.

    0 讨论(0)
  • You should use a content provider to funnel your database queries through one source. Inside of the content provider you can use any locking mechanisms you would like to ensure you're not having concurrent access. You may also think about using content observers to coordinate service actions with changes to the database.

    0 讨论(0)
提交回复
热议问题