CHAPTER 14: Android Content Providers: Providing Data to Applications 509
Note If you want to research SQLite a bit more on your own, which would be a good idea if your Android
application needs to use SQLite databases extensively, SQLite has its own website that is kept up to date on a
regular basis. Check it out at: http://www.SQLite.org.
There is a SQLite API in Android that contains all of the RDBMS functions needed to work with SQLite.
These are contained in a series of classes and methods in the android.database.sqlite package.
All you have to do is learn how to use them properly, which is not a simple task, due to the database
structure complexity which has evolved during nineteen versions of Android (4.4 API Level 19).
SQLite is designed specifically for embedded systems use similar to JavaME (Micro Edition), and
as such it has only a quarter megabyte, or 256KB, of total memory footprint. The memory space is
utilized to host a relational database engine implementation. SQLite supports a minimum (standard)
set of relational database functions and features, including the most common SQL syntax keywords,
basic database operations like READ, WRITE, and APPEND, and prepared statements. These
features are enough to provide robust Android database support.
SQLite supports three different data types: TEXT, which is known as a String value in Java,
INTEGER, which is known as a long value in Java, and REAL, which is known as a double value in
Java. When working in SQLite, all other data types must be converted into one of these compatible
data types, before entering them into a database field.
It is important to note that SQLite doesn’t validate any of the data types that may be written into its
data fields (table columns) as being one of the required data types. This means that you can write an
INTEGER value into a TEXT (String defined) data column, and vice versa, so you will always need
to pay close attention to exactly what you are doing with SQLite for this reason. If you don’t validate
what you are doing using your Java code, you may get a wrong data type result written into one of
your SQLite database fields!
To use SQLite in Android, you construct your SQLite statements for creating and (or) updating your
database, which will then be managed by Android. When your app creates a database, the database
structure will be kept in a specialized Android directory, which will always utilize the following
Android OS database path address:
DATA/data/YOUR_APPLICATION_NAME/databases/YOUR_DATABASE_FILE_NAME
Next, you will take a look at the many different types of predefined Content Providers that come
standard with the Android OS. You will also be looking at how these are accessed within the
Android operating system and its android.content package. You will also be looking at the Content
Provider and Content Resolver classes and methods used in Android to access its database
structures.
There are a plethora of Android database structures for all of the different functional areas in the OS.
This is why you are getting up to speed on this in the next section, because as you learned in the
first part of the chapter, the first step in using a DBMS is understanding its database table structure.