Defining and Launching the Query definition and start Query

Source: Internet
Author: User

To perform a query, create the CursorLoader, set up its query, and pass it to the loader framework. from then on, the framework manages everything. it runs the query on a background thread, returns the results to the foreground, and watches for changes to the data associated with the query. http://blog.csdn.net/sergeycao

Pass a CursorLoader to the loader framework in your implementation ofonCreateLoader (). the loader framework callthis method when youcreate a loader by calling initLoader (). you can create aCursorLoader anywhere, but the preferred way is to create it inonCreateLoader (), because this defers creation until the object is actually needed.

Notice that initLoader () will only onCreateLoader () if theCursorLoader doesn' t already exist; otherwise, it re-uses the existingCursorLoader. the loader framework tracks CursorLoader instance using theid value passed to initLoader ().

Define and Launch the Query
To create a CursorLoader and define its query at the same time, call the constructorCursorLoader (context, uri, projection, selection, selectionArgs, sortOrder ). thecontext and uri arguments are required, but the others are optional. to use the default value for an optional argument, pass innull. the CursorLoader runs the query against theContentProvider identified by uri, just as if you had calledContentResolver. query () with the same arguments.

For example:

Public Loader <Cursor> onCreateLoader (int loaderID, Bundle bundle)
{
/*
* Takes action based on the ID of the Loader that's being created
*/
Switch (loaderID ){
Case URL_LOADER:
/*
* Return a new CursorLoader
*/
Return new CursorLoader (
This, // Context
DataProviderContract. IMAGE_URI, // Provider's content URI
PROJECTION, // Columns to return
Null, // Return all rows
Null, // No search arguments
Null); // Default search order
Default:
// An invalid id was passed in
Return null;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.