Loader

  • 387 views
Uploaded on

Asynchronously load data in an activity or fragment.

Asynchronously load data in an activity or fragment.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
387
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
6
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Loader+Handaru Sakti
  • 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. Involved Classes and Interfaces● LoaderManager● LoaderManager.LoaderCallbacks● Loader● AsyncTaskLoader● CursorLoader
  • 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. ...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. 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. 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. DEMO LoaderTest
  • 9. References● http://developer.android.com/guide/components /loaders.html● http://developer.android.com/reference/android/ content/Loader.html