Activity. managedQuery () obtains a Cursor object containing the specified data, and the Activity takes over the life cycle of the Cursor. First, this function calls getContentResolver (). query (uri, projection, selection, selecti...
Activity. managedQuery ()
Obtain a Cursor object containing the specified data and the Activity takes over the life cycle of the Cursor.
First, this function obtains a Cursor object containing the specified data (specified by the query method parameter) by calling getContentResolver (). query (uri, projection, selection, selectionArgs, sortOrder.
Call startManagingCursor (c) to take over the life cycle of the returned Cursor c.
Prototype:
Public final Cursor managedQuery (Uri uri,
String [] projection,
String selection,
String [] selectionArgs,
String sortOrder)
{
Cursor c = getContentResolver (). query (uri, projection, selection, selectionArgs, sortOrder );
If (c! = Null ){
StartManagingCursor (c );
}
Return c;
}
Parameters:
Uri, The URI used for Content Provider query, that is, to obtain data from this URI.
For example:
Uri uri = Contacts. People. CONTENT_URI; // The URI of the contact list.
Projection, used to identify which columns in the uri need to be included in the returned Cursor object.
For example:
// ColumnsString [] projection = {
Contacts. PeopleColumns. NAME,
Contacts. PeopleColumns. NOTES
};
Selection, used as the filter parameter for queries (filtering out data that meets the selection), similar to the condition selection after the Where statement in SQL.
For example:
String selection = Contacts. People. NAME + "= ?" // Query Conditions
SelectionArgs: the query condition parameter, used with the selection parameter.
For example:
String [] selectionArgs = {"Braincol", "Nixn. dev"}; // query condition parameter
SortOrder: sort the query results by a column in the query column (columns in the projection parameter ).
For example:
String sortOrder = Contacts. lelecolumns. NAME; // sort the query result by the specified query column)
Return Value:
A Cursor object that contains the specified data.
Example:
Uri uri = Contacts. People. CONTENT_URI;
String [] projection = {Contacts. PeopleColumns. NAME,
Contacts. PeopleColumns. NOTES
};
String selection = Contacts. PeopleColumns. NAME + "=? ";
String [] selectionArgs = {"Braincol", "Nixn. dev "};
String sortOrder = Contacts. PeopleColumns. NAME;
// Use managedQuery to obtain the Contacts. People ContentProvider's Cursor.
Cursor cursor = managedQuery (uri, projection, selection, selectionArgs, sortOrder );
The preceding example indicates that the NAME is Braincol and Nixn in the contact list. the "NAME" and "NOTES" information of the two contacts in dev are sorted by NAME, and the sorted results are packaged in a Cursor object and returned.
Android. content. ContentValues
Saves the value of a single record to be inserted. ContentValues is a key/value pair dictionary.
For example:
// Fill the record with ContentValues
ContentValues values = new ContentValues ();
Values. put ("title", "New note ");
Values. put ("note", "This is a new note ");
// Tell android. content. ContentResolver to insert records using URI
ContentResolver contentResolver = new ContentResolver (); // get reference of ContentResolver
Uri newUri = contentResolver. insert (Notepad. notes. CONTENT_URI, values); // The structure of the returned newUri: Notepad. notes. CONTENT_URI/new_id
// Obtain the reference to the file output stream www.2cto.com
OutputStream outStream = contentResolver. openOutputStream (newUri );
SomeSourceBitmap. compress (Bitmap. CompressFormat. JEPG, 50, outStream );
OutStream. close ();
Author: liaoxianming