Using the SQLiteOpenHelper class
SQLiteOpenHelper
is a helper class designed to help manage database creation and
version management. To use it, you need to create a subclass of it and implement the
onCreate
,
onUpgrade
and optionally the
onOpen
methods. This class will then open
the database if it exists, create it, if it does not exist, and upgrade it when necessary.
It does all these things automatically, using the above-mentioned methods.
Now that the constants are in place and you've learned a bit about
SQLiteOpenHelper
, it's time to create the database and add the CRUD operations.
Open the
ToDoDatabaseHandler.kt
file and subclass the
SQLiteOpenHelper
, by
adding the following code after the
class
declaration:
: SQLiteOpenHelper(context, DATABASE_NAME,
null
,
DATABASE_VERSION)
The above code makes the database handler class a subclass of
Do'stlaringiz bilan baham: |