Loader+Handaru Sakti
Intoduction●   Asynchronously load data in an activity or    fragment.●   Automatically reconnect to the last their cursor...
Involved Classes and Interfaces●   LoaderManager●   LoaderManager.LoaderCallbacks●   Loader●   AsyncTaskLoader●   CursorLo...
Common Approach...●   LoaderManager to initialize a Loader. There is    only one LoaderManager per activity or    fragment...
...Common Approach●   AsyncTaskLoader: abstract loader that provides    an AsyncTask to do the work.●   A CursorLoader use...
Implementation●   Starting a Loader    –   getLoaderManager().initLoader(0, null, this);    –   Within Activity via onCrea...
Using the LoaderManager CallbacksLoaderManager.LoaderCallbacks includes thesemethods:  –   onCreateLoader() — Instantiate ...
DEMO LoaderTest
References●   http://developer.android.com/guide/components    /loaders.html●   http://developer.android.com/reference/and...
Upcoming SlideShare
Loading in...5
×

Loader

439

Published on

Asynchronously load data in an activity or fragment.

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
439
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
10
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Loader

  1. 1. Loader+Handaru Sakti
  2. 2. Intoduction● Asynchronously load data in an activity or fragment.● Automatically reconnect to the last their cursor when being recreated after a configuration change (like screen flips). Thus, they dont need to re-query their data.● Introduced in Honeycomb, exist on Android Support Package v-4.
  3. 3. Involved Classes and Interfaces● LoaderManager● LoaderManager.LoaderCallbacks● Loader● AsyncTaskLoader● CursorLoader
  4. 4. Common Approach...● LoaderManager to initialize a Loader. There is only one LoaderManager per activity or fragment, but a LoaderManager can have multiple loaders.● LoaderManager.LoaderCallbacks: a callback interface for a client to interact with the LoaderManager.● Loader: an abstract class that performs asynchronous loading of data. This is the base class for a loader.
  5. 5. ...Common Approach● AsyncTaskLoader: abstract loader that provides an AsyncTask to do the work.● A CursorLoader used to load data which backed by a ContentProvider. Alternatively, implement a subclass of Loader or AsyncTaskLoader to load data from some other source.● A SimpleCursorAdapter used to display the loader’s data.
  6. 6. Implementation● Starting a Loader – getLoaderManager().initLoader(0, null, this); – Within Activity via onCreate() method. – Within Fragment via onActivityCreated() method.● Restarting a Loader – getLoaderManager().restartLoader(0, null, this);
  7. 7. Using the LoaderManager CallbacksLoaderManager.LoaderCallbacks includes thesemethods: – onCreateLoader() — Instantiate and return a new Loader for the given ID. – onLoadFinished() — Called when a previously created Loader has finished its load. – onLoaderReset() — Called when a previously created Loader is being reset, thus making its data.
  8. 8. DEMO LoaderTest
  9. 9. References● http://developer.android.com/guide/components /loaders.html● http://developer.android.com/reference/android/ content/Loader.html
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×