Android Programming: The Big Nerd Ranch Guide, Third Edition
by Bill Phillips, Chris Stewart, Kristin Marsicano
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 whether 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, upgrade it to a newer version.
Android provides the SQLiteOpenHelper class to handle all ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access