The application uses the contentresolver client object to access data from the client. This object has the same naming methods as those in the provider. The provider is an instance of a specific subclass of contentprovider. The contentresolver object method provides the basic "crud" (create, obtain, update, and delete) Persistence saving function.
The contentresolver object in the Process of the client application and the contentprovider object in the provider's own application automatically process inter-process communication. The contentprovider object also plays the abstract layer role between the data resource library and the external performance of the data in the form of tables.
Note:To access a provisioner, you usually need to request a special license in the list file. For a more detailed description, see "content providers license"
For example, to obtain the list of words and positions from the user dictionary provider, you must call the contentresolver. Query () method. The query () method calls the contentprovider. Query () method defined by the user dictionary provider. The following code calls the contentresolver. Query () method:
// Queries the user dictionary and returns results
Mcursor = getcontentresolver (). Query (
Userdictionary. Words. content_uri, // The content URI of the words table
Mprojection, // The columns to return for each row
Mselectionclause // selection criteria
Mselectionargs, // selection criteria
Msortorder); // The sort order for the returned rows
Table 2 shows how the parameters of the query (Uri, projection, selection, selectionargs, sortorder) method match the SQL SELECT statement:
Table 2: Comparison between the query () method and SQL query.
Query () method parameters |
Select keywords/parameters |
Description |
Uri |
From table_name |
Uri maps to the table named in the provider. |
Projection |
Col ,... |
Array of columns to be selected in each row. |
Selection |
Where Col = Value |
Specify Selection Conditions |
Selectionargs |
Used to replace "?" In the selectiong Parameter . |
|
Sortorder |
Order by col, Col ,... |
Sort criteria of specified rows |