Android database approach for future updates

后端 未结 4 1872
一向
一向 2021-01-16 19:09

What is the best way to work with the sqlite database in android?

The sqlite database file (copy it for the first time into the application environment)

4条回答
  •  滥情空心
    2021-01-16 19:36

    You should create (in code) it the first time it is used. Android offers the SQLiteOpenHelper class that should be used for it. SQLiteOpenHelper defines the following methods:

    onCreate(SQLiteDatabase db): invoked when the database is created, this is where you can create tables and columns to them, create views or triggers.

    onUpgrade(SQLiteDatabse db, int oldVersion, int newVersion): Invoked if the used database is older than the current version. Handle here the upgrade stuff (data migration, table creation/deletion)

    See here for a good tutorial: http://www.codeproject.com/KB/android/AndroidSQLite.aspx

提交回复
热议问题