O'Reilly logo

Programming Android by Zigurd Mednieks, G. Blake Meike, Masumi Nakamura, Laird Dornin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A Complete Content Provider: The SimpleFinchVideoContentProvider Code

Now that you understand the important tasks associated with writing a content provider and Android MVC—the communication system for Android content providers—let’s see how to build your own content provider. The SimpleFinchVideoContentProvider class extends ContentProvider as shown here:

public class SimpleFinchVideoContentProvider extends ContentProvider {

The SimpleFinchVideoContentProvider Class and Instance Variables

As usual, it’s best to understand the major class and instance variables used by a method before examining how the method works. The member variables we need to understand for SimpleFinchVideoContentProvider are:

private static final String DATABASE_NAME = "simple_video.db";
private static final int DATABASE_VERSION = 2;
private static final String VIDEO_TABLE_NAME = "video";
private DatabaseHelper mOpenHelper;                        
DATABASE_NAME

The name of the database file on the device. For the simple Finch video, the full path to the file is /data/data/com.oreilly.demo.pa.finchvideo/databases/simple_video.db.

DATABASE_VERSION

The version of the database that is compatible with this code. If this number is higher than the database version of the database itself, the application calls the DatabaseHelper.onUpdate method.

VIDEO_TABLE_NAME

The name of the video table within the simple_video database.

mOpenHelper

The database helper instance variable that is initialized during onCreate. It provides access to the database for the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required