SQLiteDatabase close() function causing NullPointerException when multiple threads

后端 未结 4 1364
小鲜肉
小鲜肉 2020-11-30 13:00

I discovered in my project that the close() function in the SQLiteDatabase implementation on Android throws a NullPointerException when running multiple threads that open th

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-30 13:50

    I have your answers!

    Never close the db. It is that simple.

    Make sure you only have one, repeat, *one Helper instance per application. Share it with all threads.

    http://www.touchlab.co/blog/single-sqlite-connection/

    Here's some more info on the internals of sqlite and locking:

    http://www.touchlab.co/blog/android-sqlite-locking/

提交回复
热议问题