A (175)

(Tuis.) #1

506 CHAPTER 14: Android Content Providers: Providing Data to Applications


already been created and installed in the Android OS. After that, you will create a ContactGalaxy.java
Activity subclass, that will allow you to install rulers for each of your galaxies!


An Overview of Android Content Providers


The term Content Provider is unique to Android development. It means nothing more than a datastore
of data values, and is primarily found in the form of SQLite databases that are an integral part of the
Android OS.


You can use Content Provider SQLite databases that are provided in the Android OS, and you can
also create your own Content Provider databases for your application if you want, although that
topic is too advanced for an Absolute Beginner’s book. I am certain that there will soon be books
that are dedicated solely to the topic of Android SQLite database design!


An Android Content Provider provides you with access to sharable data structures, commonly called
databases, which the Android OS has chosen to use for their sharable data structures because they
have the most high-level features, which unfortunately also makes them more complicated, hence
this chapter. The general high-level procedure for utilizing a database management system (DBMS)
is as follows:



  1. Get permission to read from a given database. If you need to modify the
    database’s content, you might also need to get permission to write to that
    database.

  2. Query (search for and find) the data in the database management system
    (SQLite) using a “key,” which in Android is the _ID data field. You will be
    learning about fields very soon.

  3. Access (read into memory) the data in the database management system
    (SQLite) once you have located it using the query and _ID key.

  4. Modify (over-write, append to, or delete) the data in the database
    management system (SQLite) once you have located it, read it, and
    ascertained that it needs updating.


When accessing data, you might read the data, write to the data (change the values of the existing
data), append (add) new data onto the database structure, or delete existing data, based on the type
of permission and level of security permission that has been established for your application in its
AndroidManifest.xml file.


Data can be in Android internal (system) memory, in a SQLite database, or in an external storage
location, such as an SD card, or even on an external database server, which would also be remote to
the Android OS and to the Android device hardware.

Free download pdf