Andriod App Summary
A content provider manages access to a central repository of data. A provider is part of an Android application, which often provides its own UI for working with the data. However, content providers are primarily intended to be used by other applications, which access the provider using a provider-client object. Together, providers and provider clients offer a consistent, standard interface to data that also handles inter-process communication and secure data access.
Typically you work with content providers in one of two scenarios; you may want to implement code to access an existing content provider in another application, or you may want to create a new content provider in your application to share data with other applications. This topic covers the basics of working with existing content providers. To learn more about implementing content providers in your own applications, see Creating a content provider.
This topic describes the following:
- How content providers work.
- The API you use to retrieve data from a content provider.
- The API you use to insert, update, or delete data in a content provider.
- Other API features that facilitate working with providers.
Overview
A content provider presents data to external applications as one or more tables that are similar to the tables found in a relational database. A row represents an instance of some type of data the provider collects, and each column in the row represents an individual piece of data collected for an instance.
A content provider coordinates access to the data storage layer in your application for a number of different APIs and components as illustrated in figure 1, these include:
- Sharing access to your application data with other applications
- Sending data to a widget
- Returning custom search suggestions for your application through the search framework using
SearchRecentSuggestionsProvider
- Synchronizing application data with your server using an implementation of
AbstractThreadedSyncAdapter
- Loading data in your UI using a
CursorLoader
- Accessing a provider
When you want to access data in a content provider, you use the object in your applications to communicate with the provider as a client. The ContentResolver
object communicates with the provider object, an instance of a class that implements ContentProvider
. The provider object receives data requests from clients, performs the requested action, and returns the results. This object has methods that call identically-named methods in the provider object, an instance of one of the concrete subclasses of ContentProvider
. The ContentResolver
methods provide the basic "CRUD" (create, retrieve, update, and delete) functions of persistent storage.
A common pattern for accessing a ContentProvider
from your UI uses a CursorLoader
to run an asynchronous query in the background. The Activity
or Fragment
in your UI call a CursorLoader
to the query, which in turn gets the ContentProvider
using the ContentResolver
. This allows the UI to continue to be available to the user while the query is running. This pattern involves the interaction of a number of different objects, as well as the underlying storage mechanism, as illustrated in figure 2.
Android app activities
Contains classes for accessing and publishing data on a device. It includes three main categories of APIs:
- Content sharing (
android.content
) - For sharing content between application components. The most important classes are:
ContentProvider
andContentResolver
for managing and publishing persistent data associated with an application.Intent
andIntentFilter
, for delivering structured messages between different application components—allowing components to initiate other components and return results.- Package management (
android.content.pm
) - For accessing information about an Android package (an
.apk
), including information about its activities, permissions, services, signatures, and providers. The most important class for accessing this information isPackageManager
. - Resource management (
android.content.res
) - For retrieving resource data associated with an application, such as strings, drawables, media, and device configuration details. The most important class for accessing this data is
Resources
.
Interface
Defines a listener callback that is invoked when the primary clip on the clipboard changes. | |
The set of callback APIs that are common to all application components ( | |
Extended | |
Interface to write a stream of data to a pipe. | |
The interface that defines a dialog-type class that can be shown, dismissed, or canceled, and may have buttons that can be clicked. | |
The interface used to allow the creator of a dialog to run some code when the dialog is canceled. | |
The interface used to allow the creator of a dialog to run some code when an item on the dialog is clicked. | |
The interface used to allow the creator of a dialog to run some code when the dialog is dismissed. | |
Interface definition for a callback to be invoked when a key event is dispatched to this dialog. | |
The interface used to allow the creator of a dialog to run some code when an item in a multi-choice dialog is clicked. | |
The interface used to allow the creator of a dialog to run some code when the dialog is shown. | |
A specialization of | |
Callback interface for discovering when a send operation has completed. | |
This interface was deprecated in API level 28. Use | |
This interface was deprecated in API level 28. Use | |
Interface for monitoring the state of an application service. | |
Interface for accessing and modifying preference data returned by | |
The interface used for modifying values in a | |
Interface definition for a callback to be invoked when a shared preference is changed. | |
|
- Classes
An abstract implementation of a SyncAdapter that spawns a thread to invoke a sync operation. | |
A helper class to help make handling asynchronous | |
| |
| |
This class was deprecated in API level 28. Use the Support Library | |
Base class for code that receives and handles broadcast intents sent by | |
State for a result that is pending for a broadcast receiver. | |
Interface to the clipboard service, for placing and retrieving text in the global clipboard. | |
Representation of a clipped data on the clipboard. | |
Description of a single item in a ClipData. | |
Meta-data describing the contents of a | |
The identifier for a specific application component ( | |
Content providers are one of the primary building blocks of Android applications, providing content to applications. | |
An opaque token representing the identity of an incoming IPC. | |
The public interface object used to interact with a specific | |
Represents a single operation to be performed as part of a batch of operations. | |
Used to add parameters to a | |
Contains the result of the application of a | |
Caches the contents of a cursor into a Map of String->ContentValues and optionally keeps the cache fresh by registering for updates on the content backing the cursor. | |
This class provides applications access to the content model. | |
A detailed description of a specific MIME type, including an icon and label that describe the type. | |
Utility methods useful for working with | |
This class is used to store a set of values that the | |
Interface to global information about an application environment. | |
Proxying implementation of Context that simply delegates all of its calls to another Context. | |
This class was deprecated in API level 28. Use the Support Library | |
A representation of an item using ContentValues. | |
| |
An intent is an abstract description of an operation to be performed. | |
Wrapper class holding an Intent and implementing comparisons on it for the purpose of filtering. | |
Represents a shortcut/live folder icon resource. | |
Structured description of Intent values to be matched. | |
This is an entry for a single authority in the Iterator returned by | |
A description of an Intent and target action to perform with it. | |
Loader<D> | This class was deprecated in API level 28. Use the Support Library |
This class was deprecated in API level 28. Use | |
An identifier for a unique state (locus) in the application. | |
Special version of | |
Value type that contains information about periodic sync. | |
Constants for | |
Applications can expose restrictions for a restricted user on a multiuser device. | |
Provides a mechanism for apps to query restrictions imposed by an entity that manages the user. | |
This superclass can be used to create a simple search suggestions provider for your application. | |
Value type that represents a SyncAdapterType. | |
| |
Information about the sync operation that is currently underway. | |
Convenience class to construct sync requests. | |
Builder class for a | |
This class is used to communicate the results of a sync operation to the SyncManager. | |
Used to record various statistics about the result of a sync operation. | |
Utility class to aid in matching URIs in content providers. | |
Description of a single Uri permission grant. |
Exceptions
This exception is thrown when a call to | |
This exception is thrown when a given MIME type does not have valid syntax. | |
Exception is thrown when trying to send through a PendingIntent that has been canceled or is otherwise no longer able to execute the request. | |
Thrown when an application of a | |
This exception is thrown from |