Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

12. Content Providers > Creating a Content Provider

Creating a Content Provider

To create a content provider:

  1. Create a new Java class that subclasses the system’s ContentProvider class.

  2. Declare your CONTENT_URI.

  3. Implement all the unimplemented methods, such as insert(), update(), delete(), query(), getID(), and getType().

  4. Declare your content provider in the AndroidManifest.xml file.

We are going to start by creating a brand-new Java class in the same package as all other classes. Its name will be StatusProvider. This class, like any of Android’s main building blocks, will subclass an Android framework class, in this case ContentProvider.

In Eclipse, select your package, click on FileNewJava Class, and enter “StatusProvider”. Then, update the class to subclass ContentProvider, and organize the imports (Ctrl-Shift-O) to import the appropriate Java packages. The result should look like this:


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint