Android - Loader (Asynchronously load data)

Card Puncher Data Processing

About

Loaders provide a framework for the asynchronous loading of data.

They are registered by id in the loaderManager. The loader Id has to be unique for all loader used in the activity.

Loader asynchronously load data, see the Loaders guide.

AsyncTaskLoader is a Loader that uses an AsyncTask behind the scenes to do its work.

You can use:

Disadvantage of querying the database from the UI

From the UI = From the activity

  • The query could take a long time
  • The activity could stop before it completes
  • The cursor is tied to the activity, so if the activity restarts, the data must be re-queried

Import

Android 2.3 compatibility with the below imports. android.support.v4. is used to write apps that run on platforms prior to Android 3.0.

import android.support.v4.app.Fragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.support.v4.content.CursorLoader;

Documentation / Reference





Discover More
Card Puncher Data Processing
Android - AsyncTask

The class android/os/AsyncTaskAsyncTask simplify background thread creation. The AsyncTask is not tied to the activity lifecycle. The virtual machine will hold the AsyncTask alive as long as the AsyncTask...
Card Puncher Data Processing
Android - Thread (Background Operations)

Main Thread = UI Thread = All user input and output = Activity or fragment All long operation must not be done on the Main Thread. The class AsyncTask simplify background thread creation coupled to...



Share this page:
Follow us:
Task Runner