Android threading and database locking

后端 未结 7 1654
夕颜
夕颜 2020-12-07 10:31

We are using AsyncTasks to access database tables and cursors.

Unfortunately we are seeing occasional exceptions regarding the database being locked.

7条回答
  •  有刺的猬
    2020-12-07 11:06

    You must be calling getWritableDatabase() from a function rather then the constructor of the db helper class. If the db helper class object is created with SQLiteDatabase.openOrCreateDatabase(DB_PATH, null); or similar and then getWritableDatabase() is called from a function, it will try to make a synchronous call to DB causing a DB lock exception.

提交回复
热议问题