SQLiteDatabase close() function causing NullPointerException when multiple threads

后端 未结 4 1366
小鲜肉
小鲜肉 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:47

    If you are working directly on a SQLite database without resorting to a content provider, a pattern I have seen used is to close the database in Application.onTerminate, whereas the Application instance stores the singleton database "adapter", which would be an object containing a SQLiteDatabase and its SQLiteOpenHelper.

提交回复
热议问题