# AsyncTaskLoader

Artifact: [androidx.loader:loader](https://developer.android.com/jetpack/androidx/releases/loader) [View Source](https://cs.android.com/search?q=file:androidx/loader/content/AsyncTaskLoader.java+class:androidx.loader.content.AsyncTaskLoader) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/loader#1.0.0)

*** ** * ** ***


```
public abstract class AsyncTaskLoader<D> extends Loader<D>
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.loader.content.Loader](https://developer.android.com/reference/androidx/loader/content/Loader)\<D\> ||
|   | ↳ | [androidx.loader.content.AsyncTaskLoader](https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader) |

Known direct subclasses [CursorLoader](https://developer.android.com/reference/androidx/loader/content/CursorLoader)

|---|---|
| `https://developer.android.com/reference/androidx/loader/content/CursorLoader` | Static library support version of the framework's `https://developer.android.com/reference/android/content/CursorLoader.html`. |

*** ** * ** ***

Static library support version of the framework's `https://developer.android.com/reference/android/content/AsyncTaskLoader.html`. Used to write apps that run on platforms prior to Android 3.0. When running on Android 3.0 or above, this implementation is still used; it does not try to switch to the framework's implementation. See the framework SDK documentation for a class overview.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#AsyncTaskLoader(android.content.Context)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context)` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#cancelLoadInBackground()()` Called on the main thread to abort a load in progress. |
| `void` | `[dump](https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#dump(java.lang.String,java.io.FileDescriptor,java.io.PrintWriter,java.lang.String[]))( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html prefix, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/io/FileDescriptor.html fd, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/io/PrintWriter.html writer, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html String[] args )` **This method is deprecated.** Consider using `https://developer.android.com/reference/androidx/loader/app/LoaderManager#enableDebugLogging(boolean)` to understand the series of operations performed by LoaderManager. <br /> |
| `boolean` | `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#isLoadInBackgroundCanceled()()` Returns true if the current invocation of `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#loadInBackground()` is being canceled. |
| `abstract @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html D` | `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#loadInBackground()()` Called on a worker thread to perform the actual load and to return the result of the load operation. |
| `void` | `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#onCanceled(D)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html D data)` Called if the task was canceled before it was completed. |
| `void` | `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#setUpdateThrottle(long)(long delayMS)` Set amount to throttle updates by. |

| ### Protected methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/concurrent/Executor.html` | `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#getExecutor()()` Returns the `https://developer.android.com/reference/java/util/concurrent/Executor.html` to use for this `https://developer.android.com/reference/androidx/loader/content/Loader`'s `https://developer.android.com/reference/android/os/AsyncTask.html`s. |
| `boolean` | `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#onCancelLoad()()` Subclasses must implement this to take care of requests to `https://developer.android.com/reference/androidx/loader/content/Loader#cancelLoad()`. |
| `void` | `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#onForceLoad()()` Subclasses must implement this to take care of requests to `https://developer.android.com/reference/androidx/loader/content/Loader#forceLoad()`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html D` | `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#onLoadInBackground()()` Calls `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#loadInBackground()`. |

### Inherited methods

From [androidx.loader.content.Loader](https://developer.android.com/reference/androidx/loader/content/Loader) `void` `@https://developer.android.com/reference/androidx/annotation/MainThread
https://developer.android.com/reference/androidx/loader/content/Loader#abandon()()`

This function will normally be called for you automatically by `https://developer.android.com/reference/androidx/loader/app/LoaderManager` when restarting a Loader.
`boolean` `@https://developer.android.com/reference/androidx/annotation/MainThread
https://developer.android.com/reference/androidx/loader/content/Loader#cancelLoad()()`

Attempt to cancel the current load task.
`void` `https://developer.android.com/reference/androidx/loader/content/Loader#commitContentChanged()()`

Commit that you have actually fully processed a content change that was returned by `https://developer.android.com/reference/androidx/loader/content/Loader#takeContentChanged()`.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` `https://developer.android.com/reference/androidx/loader/content/Loader#dataToString(D)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html D data)`

For debugging, converts an instance of the Loader's data class to a string that can be printed.
`void` `@https://developer.android.com/reference/androidx/annotation/MainThread
https://developer.android.com/reference/androidx/loader/content/Loader#deliverCancellation()()`

Informs the registered `https://developer.android.com/reference/androidx/loader/content/Loader.OnLoadCanceledListener` that the load has been canceled.
`void` `@https://developer.android.com/reference/androidx/annotation/MainThread
https://developer.android.com/reference/androidx/loader/content/Loader#deliverResult(D)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html D data)`

Sends the result of the load to the registered listener.
`void` `@https://developer.android.com/reference/androidx/annotation/MainThread
https://developer.android.com/reference/androidx/loader/content/Loader#forceLoad()()`

Force an asynchronous load.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html` `https://developer.android.com/reference/androidx/loader/content/Loader#getContext()()` `int` `https://developer.android.com/reference/androidx/loader/content/Loader#getId()()` `boolean` `https://developer.android.com/reference/androidx/loader/content/Loader#isAbandoned()()`

Return whether this loader has been abandoned.
`boolean` `https://developer.android.com/reference/androidx/loader/content/Loader#isReset()()`

Return whether this load has been reset.
`boolean` `https://developer.android.com/reference/androidx/loader/content/Loader#isStarted()()`

Return whether this load has been started.
`void` `@https://developer.android.com/reference/androidx/annotation/MainThread
https://developer.android.com/reference/androidx/loader/content/Loader#onAbandon()()`

Subclasses implement this to take care of being abandoned.
`void` `@https://developer.android.com/reference/androidx/annotation/MainThread
https://developer.android.com/reference/androidx/loader/content/Loader#onContentChanged()()`

Called when `https://developer.android.com/reference/androidx/loader/content/Loader.ForceLoadContentObserver` detects a change.
`void` `@https://developer.android.com/reference/androidx/annotation/MainThread
https://developer.android.com/reference/androidx/loader/content/Loader#onReset()()`

Subclasses must implement this to take care of resetting their loader, as per `https://developer.android.com/reference/androidx/loader/content/Loader#reset()`.
`void` `@https://developer.android.com/reference/androidx/annotation/MainThread
https://developer.android.com/reference/androidx/loader/content/Loader#onStartLoading()()`

Subclasses must implement this to take care of loading their data, as per `https://developer.android.com/reference/androidx/loader/content/Loader#startLoading()`.
`void` `@https://developer.android.com/reference/androidx/annotation/MainThread
https://developer.android.com/reference/androidx/loader/content/Loader#onStopLoading()()`

Subclasses must implement this to take care of stopping their loader, as per `https://developer.android.com/reference/androidx/loader/content/Loader#stopLoading()`.
`void` `@https://developer.android.com/reference/androidx/annotation/MainThread
https://developer.android.com/reference/androidx/loader/content/Loader#registerListener(int,androidx.loader.content.Loader.OnLoadCompleteListener<D>)(
int id,
@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/loader/content/Loader.OnLoadCompleteListener<D> listener
)`

Registers a class that will receive callbacks when a load is complete.
`void` `@https://developer.android.com/reference/androidx/annotation/MainThread
https://developer.android.com/reference/androidx/loader/content/Loader#registerOnLoadCanceledListener(androidx.loader.content.Loader.OnLoadCanceledListener<D>)(
@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/loader/content/Loader.OnLoadCanceledListener<D> listener
)`

Registers a listener that will receive callbacks when a load is canceled.
`void` `@https://developer.android.com/reference/androidx/annotation/MainThread
https://developer.android.com/reference/androidx/loader/content/Loader#reset()()`

This function will normally be called for you automatically by `https://developer.android.com/reference/androidx/loader/app/LoaderManager` when destroying a Loader.
`void` `https://developer.android.com/reference/androidx/loader/content/Loader#rollbackContentChanged()()`

Report that you have abandoned the processing of a content change that was returned by `https://developer.android.com/reference/androidx/loader/content/Loader#takeContentChanged()` and would like to rollback to the state where there is again a pending content change.
`final void` `@https://developer.android.com/reference/androidx/annotation/MainThread
https://developer.android.com/reference/androidx/loader/content/Loader#startLoading()()`

This function will normally be called for you automatically by `https://developer.android.com/reference/androidx/loader/app/LoaderManager` when the associated fragment/activity is being started.
`void` `@https://developer.android.com/reference/androidx/annotation/MainThread
https://developer.android.com/reference/androidx/loader/content/Loader#stopLoading()()`

This function will normally be called for you automatically by `https://developer.android.com/reference/androidx/loader/app/LoaderManager` when the associated fragment/activity is being stopped.
`boolean` `https://developer.android.com/reference/androidx/loader/content/Loader#takeContentChanged()()`

Take the current flag indicating whether the loader's content had changed while it was stopped.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` `https://developer.android.com/reference/androidx/loader/content/Loader#toString()()` `void` `@https://developer.android.com/reference/androidx/annotation/MainThread
https://developer.android.com/reference/androidx/loader/content/Loader#unregisterListener(androidx.loader.content.Loader.OnLoadCompleteListener<D>)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/loader/content/Loader.OnLoadCompleteListener<D> listener)`

Remove a listener that was previously added with `https://developer.android.com/reference/androidx/loader/content/Loader#registerListener(int,androidx.loader.content.Loader.OnLoadCompleteListener<D>)`.
`void` `@https://developer.android.com/reference/androidx/annotation/MainThread
https://developer.android.com/reference/androidx/loader/content/Loader#unregisterOnLoadCanceledListener(androidx.loader.content.Loader.OnLoadCanceledListener<D>)(
@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/loader/content/Loader.OnLoadCanceledListener<D> listener
)`

Unregisters a listener that was previously added with `https://developer.android.com/reference/androidx/loader/content/Loader#registerOnLoadCanceledListener(androidx.loader.content.Loader.OnLoadCanceledListener<D>)`.

## Public constructors

### AsyncTaskLoader

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/loader#1.0.0)

```
public AsyncTaskLoader(@NonNull Context context)
```

## Public methods

### cancelLoadInBackground

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/loader#1.0.0)

```
public void cancelLoadInBackground()
```

Called on the main thread to abort a load in progress. Override this method to abort the current invocation of `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#loadInBackground()` that is running in the background on a worker thread. This method should do nothing if `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#loadInBackground()` has not started running or if it has already finished.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#loadInBackground()` |   |

### dump

```
public void [dump](https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#dump(java.lang.String,java.io.FileDescriptor,java.io.PrintWriter,java.lang.String[]))(
    @NonNull String prefix,
    @Nullable FileDescriptor fd,
    @NonNull PrintWriter writer,
    @Nullable String[] args
)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Consider using `https://developer.android.com/reference/androidx/loader/app/LoaderManager#enableDebugLogging(boolean)` to understand the series of operations performed by LoaderManager.

### isLoadInBackgroundCanceled

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/loader#1.0.0)

```
public boolean isLoadInBackgroundCanceled()
```

Returns true if the current invocation of `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#loadInBackground()` is being canceled.

| Returns |
|---|---|
| `boolean` | True if the current invocation of `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#loadInBackground()` is being canceled. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#loadInBackground()` |   |

### loadInBackground

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/loader#1.0.0)

```
public abstract @Nullable D loadInBackground()
```

Called on a worker thread to perform the actual load and to return the result of the load operation. Implementations should not deliver the result directly, but should return them from this method, which will eventually end up calling `https://developer.android.com/reference/androidx/loader/content/Loader#deliverResult(D)` on the UI thread. If implementations need to process the results on the UI thread they may override `https://developer.android.com/reference/androidx/loader/content/Loader#deliverResult(D)` and do so there. To support cancellation, this method should periodically check the value of `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#isLoadInBackgroundCanceled()` and terminate when it returns true. Subclasses may also override `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#cancelLoadInBackground()` to interrupt the load directly instead of polling `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#isLoadInBackgroundCanceled()`. When the load is canceled, this method may either return normally or throw `https://developer.android.com/reference/androidx/core/os/OperationCanceledException`. In either case, the `https://developer.android.com/reference/androidx/loader/content/Loader` will call `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#onCanceled(D)` to perform post-cancellation cleanup and to dispose of the result object, if any.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html D` | The result of the load operation. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/core/os/OperationCanceledException` | if the load is canceled during execution. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#isLoadInBackgroundCanceled()` |   |
| `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#cancelLoadInBackground()` |   |
| `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#onCanceled(D)` |   |

### onCanceled

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/loader#1.0.0)

```
public void onCanceled(@Nullable D data)
```

Called if the task was canceled before it was completed. Gives the class a chance to clean up post-cancellation and to properly dispose of the result.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html D data` | The value that was returned by `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#loadInBackground()`, or null if the task threw `https://developer.android.com/reference/androidx/core/os/OperationCanceledException`. |

### setUpdateThrottle

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/loader#1.0.0)

```
public void setUpdateThrottle(long delayMS)
```

Set amount to throttle updates by. This is the minimum time from when the last `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#loadInBackground()` call has completed until a new load is scheduled.

| Parameters |
|---|---|
| `long delayMS` | Amount of delay, in milliseconds. |

## Protected methods

### getExecutor

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/loader#1.1.0)

```
protected @NonNull Executor getExecutor()
```

Returns the `https://developer.android.com/reference/java/util/concurrent/Executor.html` to use for this `https://developer.android.com/reference/androidx/loader/content/Loader`'s `https://developer.android.com/reference/android/os/AsyncTask.html`s. By default `https://developer.android.com/reference/android/os/AsyncTask.html#THREAD_POOL_EXECUTOR` will be used. Override this method to return a custom executor. Note that this method will only be called once before this `https://developer.android.com/reference/androidx/loader/content/Loader`'s first `https://developer.android.com/reference/android/os/AsyncTask.html` is run. It is up to the `https://developer.android.com/reference/androidx/loader/content/Loader` to shut down the `https://developer.android.com/reference/java/util/concurrent/Executor.html` at the appropriate place (e.g. in `https://developer.android.com/reference/androidx/loader/content/Loader#onAbandon()`) if necessary.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/concurrent/Executor.html` | the `https://developer.android.com/reference/java/util/concurrent/Executor.html` to use for this `https://developer.android.com/reference/androidx/loader/content/Loader`'s `https://developer.android.com/reference/android/os/AsyncTask.html`s. |

### onCancelLoad

```
protected boolean onCancelLoad()
```

Subclasses must implement this to take care of requests to `https://developer.android.com/reference/androidx/loader/content/Loader#cancelLoad()`. This will always be called from the process's main thread.

| Returns |
|---|---|
| `boolean` | Returns false if the task could not be canceled, typically because it has already completed normally, or because `https://developer.android.com/reference/androidx/loader/content/Loader#startLoading()` hasn't been called; returns true otherwise. When true is returned, the task is still running and the `https://developer.android.com/reference/androidx/loader/content/Loader.OnLoadCanceledListener` will be called when the task completes. |

### onForceLoad

```
protected void onForceLoad()
```

Subclasses must implement this to take care of requests to `https://developer.android.com/reference/androidx/loader/content/Loader#forceLoad()`. This will always be called from the process's main thread.

### onLoadInBackground

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/loader#1.0.0)

```
protected @Nullable D onLoadInBackground()
```

Calls `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#loadInBackground()`. This method is reserved for use by the loader framework. Subclasses should override `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#loadInBackground()` instead of this method.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html D` | The result of the load operation. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/core/os/OperationCanceledException` | if the load is canceled during execution. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/loader/content/AsyncTaskLoader#loadInBackground()` |   |