In the next section, we’ll examine some code from Chapter 12
that deals with persistent storage of video-related metadata
information: title, description, and video URL. This code resides
inside an Android content provider, which we feel is an appropriate
location for database code. Without explaining much about content
providers, we’ll discuss how to write a database for one. Chapter 12 explains in detail how to write a content
provider. The following code will help us illustrate how to create and
use an SQLite database in Android. This application will use roughly
the same database that we just examined using the
sqlite3 command-line tool. This time,
though, we’ll be writing code that uses the Android API to manipulate
In our example, the SimpleFinchVideoContentProvider.java file encapsulates all the SQL logic necessary to work with the simple_video database in Android. Applications that need access to the persistent data in this database interact with the provider and the cursors it supplies, as we’ll explain in Chapter 12. Clients are completely insulated from the details of how the data is actually stored. This is good programming practice and should be emulated in all your Android applications that use databases.
For now, since we are focusing on how to
use databases in Android, it’s sufficient to know that
SimpleVideoDbHelper is the model of the database in the provider: everything ...