Android simultaneous db operations — “database is locked”

霸气de小男生 提交于 2019-12-01 21:50:28

If your activity is only going to read and not write to database like my case, this is what i did as a workaround:

  • create a service ( i.e DatabaseService 0 and use it as a central point to access database (i.e open a database connection) to ensure you only have one dbhelper at a time.
  • all activity and service which need to access database have to establish a connection to DatabaseService
  • ensure that only your DownloadService's thread is able to write to database and it should use transaction
  • after that, you can use getReadable database to read / use the connection to stop the download service , etc.

Just make sure that you only use 1 dbhelper.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!