Stay organized with collections
Save and categorize content based on your preferences.
LoaderManager.LoaderCallbacks
public
static
interface
LoaderManager.LoaderCallbacks
android.app.LoaderManager.LoaderCallbacks<D>
|
This interface was deprecated
in API level 28.
Use the
Support Library LoaderManager.LoaderCallbacks
Callback interface for a client to interact with the manager.
Summary
Public methods |
abstract
Loader<D>
|
onCreateLoader(int id, Bundle args)
Instantiate and return a new Loader for the given ID.
|
abstract
void
|
onLoadFinished(Loader<D> loader, D data)
Called when a previously created loader has finished its load.
|
abstract
void
|
onLoaderReset(Loader<D> loader)
Called when a previously created loader is being reset, and thus
making its data unavailable.
|
Public methods
onCreateLoader
public abstract Loader<D> onCreateLoader (int id,
Bundle args)
Instantiate and return a new Loader for the given ID.
Parameters |
id |
int : The ID whose loader is to be created. |
args |
Bundle : Any arguments supplied by the caller. |
Returns |
Loader<D> |
Return a new Loader instance that is ready to start loading. |
onLoadFinished
public abstract void onLoadFinished (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 FragmentManager.openTransaction()
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 Cursor
and you place it in a CursorAdapter
, use
the CursorAdapter.CursorAdapter(android.content.Context, android.database.Cursor, int)
constructor without passing
in either CursorAdapter.FLAG_AUTO_REQUERY
or CursorAdapter.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
Cursor
from a CursorLoader
,
you should not call close() on it yourself. If the Cursor is being placed in a
CursorAdapter
, you should use the
CursorAdapter.swapCursor(android.database.Cursor)
method so that the old Cursor is not closed.
Parameters |
loader |
Loader : The Loader that has finished. |
data |
D : The data generated by the Loader. |
onLoaderReset
public abstract void onLoaderReset (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.
Parameters |
loader |
Loader : The Loader that is being reset. |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# LoaderManager.LoaderCallbacks\n\nAdded in [API level 11](/guide/topics/manifest/uses-sdk-element#ApiLevels) \nDeprecated in [API level\n28](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\nLoaderManager.LoaderCallbacks\n=============================\n\n*** ** * ** ***\n\n[Kotlin](/reference/kotlin/android/app/LoaderManager.LoaderCallbacks \"View this page in Kotlin\") \\|Java\n\n\n`\npublic\nstatic\n\n\ninterface\nLoaderManager.LoaderCallbacks\n`\n\n\n`\n\n\n`\n\n|------------------------------------------------|\n| android.app.LoaderManager.LoaderCallbacks\\\u003cD\\\u003e |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\n\n**This interface was deprecated\nin API level 28.** \n\nUse the [Support Library](/tools/extras/support-library) [LoaderManager.LoaderCallbacks](https://developer.android.com/reference/androidx/loader/app/LoaderManager.LoaderCallbacks.html)\n\nCallback interface for a client to interact with the manager.\n\nSummary\n-------\n\n| ### Public methods ||\n|--------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` abstract `[Loader](/reference/android/content/Loader)`\u003cD\u003e` | ` `[onCreateLoader](/reference/android/app/LoaderManager.LoaderCallbacks#onCreateLoader(int,%20android.os.Bundle))`(int id, `[Bundle](/reference/android/os/Bundle)` args) ` Instantiate and return a new Loader for the given ID. |\n| ` abstract void` | ` `[onLoadFinished](/reference/android/app/LoaderManager.LoaderCallbacks#onLoadFinished(android.content.Loader\u003cD\u003e,%20D))`(`[Loader](/reference/android/content/Loader)`\u003cD\u003e loader, D data) ` Called when a previously created loader has finished its load. |\n| ` abstract void` | ` `[onLoaderReset](/reference/android/app/LoaderManager.LoaderCallbacks#onLoaderReset(android.content.Loader\u003cD\u003e))`(`[Loader](/reference/android/content/Loader)`\u003cD\u003e loader) ` Called when a previously created loader is being reset, and thus making its data unavailable. |\n\nPublic methods\n--------------\n\n### onCreateLoader\n\nAdded in [API level 11](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract Loader\u003cD\u003e onCreateLoader (int id, \n Bundle args)\n```\n\nInstantiate and return a new Loader for the given ID.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|--------|--------------------------------------------------------|\n| `id` | `int`: The ID whose loader is to be created. \u003cbr /\u003e |\n| `args` | `Bundle`: Any arguments supplied by the caller. \u003cbr /\u003e |\n\n| Returns ||\n|--------------------------------------------------|---------------------------------------------------------------------|\n| [Loader](/reference/android/content/Loader)`\u003cD\u003e` | Return a new Loader instance that is ready to start loading. \u003cbr /\u003e |\n\n### onLoadFinished\n\nAdded in [API level 11](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract void onLoadFinished (Loader\u003cD\u003e loader, \n D data)\n```\n\nCalled when a previously created loader has finished its load. Note\nthat normally an application is *not* allowed to commit fragment\ntransactions while in this call, since it can happen after an\nactivity's state is saved. See [FragmentManager.openTransaction()](/reference/android/app/FragmentManager#beginTransaction()) for further discussion on this.\n\nThis function is guaranteed to be called prior to the release of\nthe last data that was supplied for this Loader. At this point\nyou should remove all use of the old data (since it will be released\nsoon), but should not do your own release of the data since its Loader\nowns it and will take care of that. The Loader will take care of\nmanagement of its data so you don't have to. In particular:\n\n- The Loader will monitor for changes to the data, and report\n them to you through new calls here. You should not monitor the\n data yourself. For example, if the data is a [Cursor](/reference/android/database/Cursor)\n and you place it in a [CursorAdapter](/reference/android/widget/CursorAdapter), use\n the [CursorAdapter.CursorAdapter(android.content.Context, android.database.Cursor, int)](/reference/android/widget/CursorAdapter#CursorAdapter(android.content.Context,%20android.database.Cursor,%20int)) constructor *without* passing\n in either [CursorAdapter.FLAG_AUTO_REQUERY](/reference/android/widget/CursorAdapter#FLAG_AUTO_REQUERY)\n or [CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER](/reference/android/widget/CursorAdapter#FLAG_REGISTER_CONTENT_OBSERVER)\n (that is, use 0 for the flags argument). This prevents the CursorAdapter\n from doing its own observing of the Cursor, which is not needed since\n when a change happens you will get a new Cursor throw another call\n here.\n\n- The Loader will release the data once it knows the application is no longer using it. For example, if the data is a [Cursor](/reference/android/database/Cursor) from a [CursorLoader](/reference/android/content/CursorLoader), you should not call close() on it yourself. If the Cursor is being placed in a [CursorAdapter](/reference/android/widget/CursorAdapter), you should use the [CursorAdapter.swapCursor(android.database.Cursor)](/reference/android/widget/CursorAdapter#swapCursor(android.database.Cursor)) method so that the old Cursor is not closed.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Parameters ||\n|----------|------------------------------------------------|\n| `loader` | `Loader`: The Loader that has finished. \u003cbr /\u003e |\n| `data` | `D`: The data generated by the Loader. \u003cbr /\u003e |\n\n### onLoaderReset\n\nAdded in [API level 11](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract void onLoaderReset (Loader\u003cD\u003e loader)\n```\n\nCalled when a previously created loader is being reset, and thus\nmaking its data unavailable. The application should at this point\nremove any references it has to the Loader's data.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|----------|--------------------------------------------------|\n| `loader` | `Loader`: The Loader that is being reset. \u003cbr /\u003e |"]]