1 page.title=Loading Data in the Background 2 trainingnavtop=true 3 startpage=true 4 5 @jd:body 6 <div id="tb-wrapper"> 7 <div id="tb"> 8 9 <!-- Required platform, tools, add-ons, devices, knowledge, etc. --> 10 <h2>Dependencies and prerequisites</h2> 11 <h3>Dependencies</h3> 12 <ul> 13 <li> 14 Android 1.6 or later 15 </li> 16 </ul> 17 <h3>Prerequisites</h3> 18 <ul> 19 <li> 20 <a href="{@docRoot}training/basics/firstapp/index.html">Building Your First App</a> class 21 </li> 22 <li> 23 <a href="{@docRoot}training/basics/activity-lifecycle/index.html"> 24 Managing the Activity Lifecycle</a> class 25 </li> 26 </ul> 27 28 <!-- related docs (NOT javadocs) --> 29 <h2>You should also read</h2> 30 <ul> 31 <li> 32 <a href="{@docRoot}guide/components/loaders.html">Loaders</a> 33 </li> 34 <li> 35 <a href="{@docRoot}guide/topics/data/data-storage.html#db">Using Databases</a> 36 </li> 37 <li> 38 <a href="{@docRoot}guide/topics/providers/content-provider-basics.html">Content Provider Basics</a> 39 </li> 40 </ul> 41 </div> 42 </div> 43 <p> 44 A {@link android.support.v4.content.CursorLoader} runs a query against a 45 {@link android.content.ContentProvider} on a background thread and returns a 46 {@link android.database.Cursor} to the main thread. 47 </p> 48 <p> 49 {@link android.support.v4.content.CursorLoader} has these advantages over alternate ways of 50 running a query: 51 </p> 52 <dl> 53 <dt> 54 Query on a background thread 55 </dt> 56 <dd> 57 A {@link android.support.v4.content.CursorLoader} query runs asynchronously on a 58 background thread, so it doesn't cause "Application Not Responding" (ANR) errors on the UI 59 thread. {@link android.support.v4.content.CursorLoader} creates and starts the 60 background thread; all you have to do is initialize the loader framework and handle the 61 results of the query. 62 </dd> 63 <dt> 64 Automatic re-query 65 </dt> 66 <dd> 67 A {@link android.support.v4.content.CursorLoader} automatically runs a new query when 68 the loader framework detects that the data underlying the {@link android.database.Cursor} 69 has changed. 70 </dd> 71 <dt> 72 Simple API 73 </dt> 74 <dd> 75 The {@link android.support.v4.content.CursorLoader} API provides the 76 query framework and cursor monitoring that you would have to define yourself if you used 77 {@link android.os.AsyncTask}. 78 </dd> 79 </dl> 80 <p> 81 A {@link android.support.v4.content.CursorLoader} is limited in that the query must be 82 against a {@link android.net.Uri} and must return a {@link android.database.Cursor}. Because of 83 this, a {@link android.support.v4.content.CursorLoader} can only run a query against a 84 {@link android.content.ContentProvider}. 85 </p> 86 <p> 87 This class describes how to define and use a {@link android.support.v4.content.CursorLoader}. 88 Examples in this class use the {@link android.support.v4 v4 support library} versions of 89 classes, which support platforms starting with Android 1.6. 90 </p> 91 <h2>Lessons</h2> 92 <dl> 93 <dt> 94 <strong><a href="setup-loader.html">Setting Up the Loader</a></strong> 95 </dt> 96 <dd> 97 Learn how to set up an {@link android.app.Activity} that inherits the necessary classes 98 for running a {@link android.support.v4.content.CursorLoader} and returning results. 99 </dd> 100 <dt> 101 <strong><a href="define-launch-query.html">Defining and Launching the Query</a></strong> 102 </dt> 103 <dd> 104 Learn how to perform a query against a {@link android.content.ContentProvider} using 105 a {@link android.support.v4.content.CursorLoader}. 106 </dd> 107 <dt> 108 <strong> 109 <a href="handle-results.html">Handling the Results</a> 110 </strong> 111 </dt> 112 <dd> 113 Learn how to handle the {@link android.database.Cursor} returned from the query, and how 114 to remove references to the current {@link android.database.Cursor} when the loader 115 framework re-sets the {@link android.support.v4.content.CursorLoader}. 116 </dd> 117 </dl> 118