Building Your Initial Database
With your schema defined, you are ready to create the database itself. Android provides some low-level methods on Context to open a database file into an instance of SQLiteDatabase: openOrCreateDatabase(…) and databaseList().
However, in practice you will always need to follow a few basic steps:
-
Check to see if the database already exists.
-
If it does not, create it and create the tables and initial data it needs.
-
If it does, open it up and see what version of your CrimeDbSchema it has. (You may want to add or remove things in future versions of CriminalIntent.)
-
If it is an old version, run code to upgrade it to a newer version.
Android provides the SQLiteOpenHelper class to handle ...
Get Android Programming: The Big Nerd Ranch Guide, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.