Home > Articles > Home & Office Computing > Entertainment/Gaming/Gadgets

Content Providers: Android's Data Sharing Mechanisms

  • Print
  • + Share This
Content providers, which are part of the building blocks of the Android platform, share data between applications. In this article, Carl-Gustaf Harroch focuses on the data-sharing mechanism offered by Android (in reference to Android release v0.5).
Like this article? We recommend

Like this article? We recommend

Content providers, which are part of the building blocks of the Android platform, are the only way to share data between applications. This article will focus on the data-sharing mechanism offered by Android. I will explain the benefits and drawbacks of content providers and then demonstrate the use of content providers to handle a one-to-many relationship within a database. I will then take this example further to show some standard URIs to further narrow data via the interface.

This article presumes some previous experience with Android platform concepts such as intents and resolving of mime types. This article was written in reference to Android release v0.5.

Permission and Application Space

As is the norm with Linux, when you install a new application, the process will run within its own user and group id. Through the Android sdk's packaged adb emulator, if you list the files (ls -l command) within the path '/data/data', different user ids will be shown for each application.

Contrary to the standard JVM, the Dalvik JVM uses one process per application. You can view your own application and its corresponding user id using the 'ps' command. Inbuilt Linux security will deny your application access to any data located within the folder of another application. There is no shared folder that can be used by several applications

In order to communicate data between processes you need to define an interface for data sharing. This interface is called ContentProvider. Any data you want to be shared needs to be exposed by a class that implements the ContentProvider interface.

After creating a class that implements the five abstract methods of the ContentProvider interface, you need to register it with the system. This is done within your application's AndroidManifest file.

The Android platform scans all manifest files for content providers that will then be registered. This system-wide data is then accessed via the Android ContentResolver interface.

  • + Share This
  • 🔖 Save To Your Account