Cannot open SQLite database from SQLIte Helper Oncreate, when OnCreate is triggered by opening database for the first time

前端 未结 2 1771
野性不改
野性不改 2020-12-20 08:59

When the mainactivity tries to open the database for the first time after the app is installed, the SQLiteHelper Oncreate method is triggered (as one would expect). I want

2条回答
  •  感情败类
    2020-12-20 09:53

    You should not attempt to call getWritableDatabase() or getReadableDatabase() from SQLiteOpenHelper lifecycle methods such as onCreate() or methods called from there. That will fail with a "called recursively" exception.

    Instead, use the SQLiteDatabase that is given as a parameter to onCreate() or other lifecycle methods.

提交回复
热议问题