Loader

suggest change

Versions

This topic was documented against Android 3.0 through 7.1.

Introduction

A loader is a good choice when you load data in the background from onCreate and want to avoid leaking the old activity or starting a second load after rotation. If you execute an AsyncTask in onCreate and rotate the screen, the activity is recreated and starts another AsyncTask, so two tasks can run in parallel. A loader continues the background work that was already started.

Parameters

Class Description
LoaderManager An abstract class associated with an Activity or Fragment for managing one or more Loader instances.
LoaderManager.LoaderCallbacks A callback interface for a client to interact with the LoaderManager.
Loader An abstract class that performs asynchronous loading of data.
AsyncTaskLoader Abstract loader that provides an AsyncTask to do the work.
CursorLoader A subclass of AsyncTaskLoader that queries the ContentResolver and returns a Cursor.

Remarks

Introduced in Android 3.0, loaders make it easy to asynchronously load data in an activity or fragment. Loaders have these characteristics:

When not to use Loaders

Avoid loaders when the background work has to run to completion. Android destroys loaders with the activities and fragments they belong to. For work that must finish after that, use a service.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents