# LoaderManager.LoaderCallbacks

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

*** ** * ** ***


```
public interface LoaderManager.LoaderCallbacks<D>
```

<br />

*** ** * ** ***

Callback interface for a client to interact with the manager.

## Summary

| ### Public methods |
|---|---|
| `abstract @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/loader/content/Loader<D>` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/loader/app/LoaderManager.LoaderCallbacks#onCreateLoader(int,android.os.Bundle)(int id, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/os/Bundle.html args)` Instantiate and return a new Loader for the given ID. |
| `abstract void` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/loader/app/LoaderManager.LoaderCallbacks#onLoadFinished(androidx.loader.content.Loader<D>,D)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/loader/content/Loader<D> loader, D data)` Called when a previously created loader has finished its load. |
| `abstract void` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/loader/app/LoaderManager.LoaderCallbacks#onLoaderReset(androidx.loader.content.Loader<D>)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/loader/content/Loader<D> loader)` Called when a previously created loader is being reset, and thus making its data unavailable. |

## Public methods

### onCreateLoader

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

```
@MainThread
abstract @NonNull Loader<D> onCreateLoader(int id, @Nullable Bundle args)
```

Instantiate and return a new Loader for the given ID.

This will always be called from the process's main thread.

| Parameters |
|---|---|
| `int id` | The ID whose loader is to be created. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/os/Bundle.html args` | Any arguments supplied by the caller. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/loader/content/Loader<D>` | Return a new Loader instance that is ready to start loading. |

### onLoadFinished

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

```
@MainThread
abstract void onLoadFinished(@NonNull Loader<D> loader, D data)
```

Called when a previously created loader has finished its load. Note that normally an application is *not* allowed to commit fragment transactions while in this call, since it can happen after an activity's state is saved. See `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#beginTransaction()` for further discussion on this.

This function is guaranteed to be called prior to the release of the last data that was supplied for this Loader. At this point you should remove all use of the old data (since it will be released soon), but should not do your own release of the data since its Loader owns it and will take care of that. The Loader will take care of management of its data so you don't have to. In particular:

- The Loader will monitor for changes to the data, and report them to you through new calls here. You should not monitor the data yourself. For example, if the data is a `https://developer.android.com/reference/android/database/Cursor.html` and you place it in a `https://developer.android.com/reference/android/widget/CursorAdapter.html`, use the `https://developer.android.com/reference/android/widget/CursorAdapter.html#CursorAdapter(android.content.Context, android.database.Cursor, int)` constructor *without* passing in either `https://developer.android.com/reference/android/widget/CursorAdapter.html#FLAG_AUTO_REQUERY` or `https://developer.android.com/reference/android/widget/CursorAdapter.html#FLAG_REGISTER_CONTENT_OBSERVER` (that is, use 0 for the flags argument). This prevents the CursorAdapter from doing its own observing of the Cursor, which is not needed since when a change happens you will get a new Cursor throw another call here.

- The Loader will release the data once it knows the application is no longer using it. For example, if the data is a `https://developer.android.com/reference/android/database/Cursor.html` from a `https://developer.android.com/reference/android/content/CursorLoader.html`, you should not call close() on it yourself. If the Cursor is being placed in a `https://developer.android.com/reference/android/widget/CursorAdapter.html`, you should use the `https://developer.android.com/reference/android/widget/CursorAdapter.html#swapCursor(android.database.Cursor)` method so that the old Cursor is not closed.

This will always be called from the process's main thread.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/loader/content/Loader<D> loader` | The Loader that has finished. |
| `D data` | The data generated by the Loader. |

### onLoaderReset

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

```
@MainThread
abstract void onLoaderReset(@NonNull Loader<D> loader)
```

Called when a previously created loader is being reset, and thus making its data unavailable. The application should at this point remove any references it has to the Loader's data.

This will always be called from the process's main thread.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/loader/content/Loader<D> loader` | The Loader that is being reset. |