When the SQLiteOpenHelper onCreate method is called?

前端 未结 4 942
野性不改
野性不改 2020-12-09 15:30

I tried to create an SQLite database and do some stuff with it. But I found that my onCreate method is not even invoked!!

I am sending a message to LogC

4条回答
  •  爱一瞬间的悲伤
    2020-12-09 16:04

    As the official documents says, "getWritableDatabase () Create and/or open a database that will be used for reading and writing. The first time this is called, the database will be opened and onCreate(SQLiteDatabase), onUpgrade(SQLiteDatabase, int, int) and/or onOpen(SQLiteDatabase) will be called."

    Once opened successfully, the database is cached, so you can call this method every time you need to write to the database. (Make sure to call close() when you no longer need the database.) Errors such as bad permissions or a full disk may cause this method to fail, but future attempts may succeed if the problem is fixed.

    http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#getWritableDatabase()

提交回复
热议问题