Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are two key benefits to using a <code>CursorLoader</code> in your app over <code>Activity.managedQuery():</code></p> <ol> <li>The query is handled on a background thread for you (courtesy of being build on <code>AsyncTaskLoader)</code> so large data queries do not block the UI. This is something the docs recommended you do for yourself when using a plain <code>Cursor</code>, but now it's done under the hood.</li> <li><code>CursorLoader</code> is auto-updating. In addition to performing the initial query, the CursorLoader registers a <code>ContentObserver</code> with the dataset you requested and calls <code>forceLoad()</code> on itself when the data set changes. This results in you getting <code>async</code> callbacks anytime the data changes in order to update the view.</li> </ol> <p>Each Loader instance is also handled through the singular <code>LoaderManager</code>, so you still don't have to manage the cursor directly, and now the connection can persist even beyond a single <code>Activity. LoaderManager.initLoader()</code> and <code>LoaderManager.restartLoader()</code> allow you to reconnect with an existing Loader already set up for your query and, in some cases, instantly get the latest data if it is available.</p> <p>Your Activity or Fragment will likely now implement the <code>LoaderManager</code>.Callback interface. Calling <code>initLoader()</code> will result in the onCreateLoader() method where you will construct the query and a new <code>CursorLoader</code> instance, if necessary. The <code>onLoadFinished()</code> method will be fired each time new data is available, and will include the latest Cursor for you to attach to the view or otherwise iterate through.</p> <p>In addition, there is a pretty good example of all this fitting together on the <code>LoaderManager</code> class documentation page: <a href="http://developer.android.com/reference/android/app/LoaderManager.html" rel="nofollow">http://developer.android.com/reference/android/app/LoaderManager.html</a></p> <p>Hope that Helps!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload