summaryrefslogtreecommitdiffstats
path: root/docs/html/training/load-data-background/index.jd
blob: 574a32cc0e40de726cf71b13881545f1917c6e7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
page.title=Loading Data in the Background
trainingnavtop=true
startpage=true

@jd:body
<div id="tb-wrapper">
<div id="tb">

<!-- Required platform, tools, add-ons, devices, knowledge, etc. -->
<h2>Dependencies and prerequisites</h2>
<h3>Dependencies</h3>
<ul>
    <li>
        Android 1.6 or later
    </li>
</ul>
<h3>Prerequisites</h3>
<ul>
    <li>
        <a href="{@docRoot}training/basics/firstapp/index.html">Building Your First App</a> class
    </li>
    <li>
        <a href="{@docRoot}training/basics/activity-lifecycle/index.html">
        Managing the Activity Lifecycle</a> class
    </li>
</ul>

<!-- related docs (NOT javadocs) -->
<h2>You should also read</h2>
<ul>
    <li>
        <a href="{@docRoot}guide/components/loaders.html">Loaders</a>
    </li>
    <li>
        <a href="{@docRoot}guide/topics/data/data-storage.html#db">Using Databases</a>
    </li>
    <li>
<a href="{@docRoot}guide/topics/providers/content-provider-basics.html">Content Provider Basics</a>
    </li>
</ul>
</div>
</div>
<p>
    A {@link android.support.v4.content.CursorLoader} runs a query against a
    {@link android.content.ContentProvider} on a background thread and returns a
    {@link android.database.Cursor} to the main thread.
</p>
<p>
    {@link android.support.v4.content.CursorLoader} has these advantages over alternate ways of
    running a query:
</p>
<dl>
    <dt>
        Query on a background thread
    </dt>
    <dd>
        A {@link android.support.v4.content.CursorLoader} query runs asynchronously on a
        background thread, so it doesn't cause "Application Not Responding" (ANR) errors on the UI
        thread. {@link android.support.v4.content.CursorLoader} creates and starts the
        background thread; all you have to do is initialize the loader framework and handle the
        results of the query.
    </dd>
    <dt>
        Automatic re-query
    </dt>
    <dd>
        A {@link android.support.v4.content.CursorLoader} automatically runs a new query when
        the loader framework detects that the data underlying the {@link android.database.Cursor}
        has changed.
    </dd>
    <dt>
        Simple API
    </dt>
    <dd>
        The {@link android.support.v4.content.CursorLoader} API provides the
        query framework and cursor monitoring that you would have to define yourself if you used
        {@link android.os.AsyncTask}.
    </dd>
</dl>
<p>
    A {@link android.support.v4.content.CursorLoader} is limited in that the query must be
    against a {@link android.net.Uri} and must return a {@link android.database.Cursor}. Because of
    this, a {@link android.support.v4.content.CursorLoader} can only run a query against a
    {@link android.content.ContentProvider}.
</p>
<p>
    This class describes how to define and use a {@link android.support.v4.content.CursorLoader}.
    Examples in this class use the {@link android.support.v4 v4 support library} versions of
    classes, which support platforms starting with Android 1.6.
</p>
<h2>Lessons</h2>
<dl>
    <dt>
        <strong><a href="setup-loader.html">Setting Up the Loader</a></strong>
    </dt>
    <dd>
        Learn how to set up an {@link android.app.Activity} that inherits the necessary classes
        for running a {@link android.support.v4.content.CursorLoader} and returning results.
    </dd>
    <dt>
        <strong><a href="define-launch-query.html">Defining and Launching the Query</a></strong>
    </dt>
    <dd>
        Learn how to perform a query against a {@link android.content.ContentProvider} using
        a {@link android.support.v4.content.CursorLoader}.
    </dd>
    <dt>
        <strong>
        <a href="handle-results.html">Handling the Results</a>
        </strong>
    </dt>
    <dd>
        Learn how to handle the {@link android.database.Cursor} returned from the query, and how
        to remove references to the current {@link android.database.Cursor} when the loader
        framework re-sets the {@link android.support.v4.content.CursorLoader}.
    </dd>
</dl>