Android - Loader (Asynchronously load data)

> Android

1 - 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:

Advertising

3 - 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

4 - 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;

5 - Documentation / Reference