When the SQLiteOpenHelper onCreate method is called?

前端 未结 4 949
野性不改
野性不改 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:07

    Your are right, the (super) constructor will invoke onCreate method, BUT only if the actual database does not exits. From http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#onCreate%28android.database.sqlite.SQLiteDatabase%29

    A helper class to manage database creation and version management.

    You create a subclass implementing onCreate(SQLiteDatabase), onUpgrade(SQLiteDatabase, int, int) and optionally onOpen(SQLiteDatabase), and this class takes care of opening the database if it exists, creating it if it does not, and upgrading it as necessary.

提交回复
热议问题