Stay organized with collections
Save and categorize content based on your preferences.
LoaderCallbacks
interface LoaderCallbacks<D : Any!>
Callback interface for a client to interact with the manager.
Summary
Public methods |
abstract Loader<D>! |
Instantiate and return a new Loader for the given ID.
|
abstract Unit |
Called when a previously created loader has finished its load.
|
abstract Unit |
Called when a previously created loader is being reset, and thus making its data unavailable.
|
Public methods
onCreateLoader
abstract fun onCreateLoader(
id: Int,
args: Bundle!
): Loader<D>!
Deprecated: Deprecated in Java.
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. |
Return |
Loader<D>! |
Return a new Loader instance that is ready to start loading. |
onLoadFinished
abstract fun onLoadFinished(
loader: Loader<D>!,
data: D
): Unit
Deprecated: Deprecated in Java.
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 android.database.Cursor
and you place it in a android.widget.CursorAdapter
, use the android.widget.CursorAdapter#CursorAdapter(android.content.Context, * android.database.Cursor, int)
constructor without passing in either android.widget.CursorAdapter#FLAG_AUTO_REQUERY
or android.widget.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
android.database.Cursor
from a android.content.CursorLoader
, you should not call close() on it yourself. If the Cursor is being placed in a android.widget.CursorAdapter
, you should use the android.widget.CursorAdapter#swapCursor(android.database.Cursor)
method so that the old Cursor is not closed.
Parameters |
loader |
Loader<D>!: The Loader that has finished. |
data |
D: The data generated by the Loader. |
onLoaderReset
abstract fun onLoaderReset(loader: Loader<D>!): Unit
Deprecated: Deprecated in Java.
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<D>!: 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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# LoaderManager.LoaderCallbacks\n\nAdded in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \nDeprecated in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nLoaderCallbacks\n===============\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/app/LoaderManager.LoaderCallbacks \"View this page in Java\") \n\n```\ninterface LoaderCallbacks\u003cD : Any!\u003e\n```\n\n|------------------------------------------------|\n| [android.app.LoaderManager.LoaderCallbacks](#) |\n\n*** ** * ** ***\n\n| **This interface was deprecated in API level 28.**\n|\n| Use the [Support Library](https://developer.android.com/tools/extras/support-library.html) androidx.loader.app.LoaderManager.LoaderCallbacks\n\nCallback interface for a client to interact with the manager.\n\nSummary\n-------\n\n| Public methods ||\n|---------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [Loader](../content/Loader.html#)\\\u003cD\\\u003e! | [onCreateLoader](#onCreateLoader(kotlin.Int,%20android.os.Bundle))`(`id:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `args:` `[Bundle](../os/Bundle.html#)!`)` Instantiate and return a new Loader for the given ID. |\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onLoadFinished](#onLoadFinished(android.content.Loader,%20android.app.LoaderManager.LoaderCallbacks.D))`(`loader:` `[Loader](../content/Loader.html#)\u003cD\u003e!`, `data:` `D`)` Called when a previously created loader has finished its load. |\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onLoaderReset](#onLoaderReset(android.content.Loader))`(`loader:` `[Loader](../content/Loader.html#)\u003cD\u003e!`)` 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](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun onCreateLoader(\n id: Int, \n args: Bundle!\n): Loader\u003cD\u003e!\n```\n\n**Deprecated:** *Deprecated in Java.*\n\nInstantiate and return a new Loader for the given ID.\n\n| Parameters ||\n|--------|-------------------------------------------------------------------------------------------------------------------|\n| `id` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): The ID whose loader is to be created. |\n| `args` | [Bundle](../os/Bundle.html#)!: Any arguments supplied by the caller. |\n\n| Return ||\n|---------------------------------------|--------------------------------------------------------------|\n| [Loader](../content/Loader.html#)\u003cD\u003e! | Return a new Loader instance that is ready to start loading. |\n\n### onLoadFinished\n\nAdded in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun onLoadFinished(\n loader: Loader\u003cD\u003e!, \n data: D\n): Unit\n```\n\n**Deprecated:** *Deprecated in Java.*\n\nCalled 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()](/reference/kotlin/android/app/FragmentManager#beginTransaction()) for further discussion on this.\n\nThis 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:\n\n- 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 [android.database.Cursor](../database/Cursor.html#) and you place it in a [android.widget.CursorAdapter](../widget/CursorAdapter.html#), use the [android.widget.CursorAdapter#CursorAdapter(android.content.Context, * android.database.Cursor, int)](../widget/CursorAdapter.html#CursorAdapter(android.content.Context,%20android.database.Cursor,%20kotlin.Int)) constructor *without* passing in either [android.widget.CursorAdapter#FLAG_AUTO_REQUERY](../widget/CursorAdapter.html#FLAG_AUTO_REQUERY:kotlin.Int) or [android.widget.CursorAdapter#FLAG_REGISTER_CONTENT_OBSERVER](../widget/CursorAdapter.html#FLAG_REGISTER_CONTENT_OBSERVER:kotlin.Int) (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.\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 [android.database.Cursor](../database/Cursor.html#) from a [android.content.CursorLoader](../content/CursorLoader.html#), you should not call close() on it yourself. If the Cursor is being placed in a [android.widget.CursorAdapter](../widget/CursorAdapter.html#), you should use the [android.widget.CursorAdapter#swapCursor(android.database.Cursor)](../widget/CursorAdapter.html#swapCursor(android.database.Cursor)) method so that the old Cursor is not closed.\n\n| Parameters ||\n|----------|------------------------------------------------------------------------|\n| `loader` | [Loader](../content/Loader.html#)\\\u003cD\\\u003e!: The Loader that has finished. |\n| `data` | D: The data generated by the Loader. |\n\n### onLoaderReset\n\nAdded in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun onLoaderReset(loader: Loader\u003cD\u003e!): Unit\n```\n\n**Deprecated:** *Deprecated in Java.*\n\nCalled 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.\n\n| Parameters ||\n|----------|--------------------------------------------------------------------------|\n| `loader` | [Loader](../content/Loader.html#)\\\u003cD\\\u003e!: The Loader that is being reset. |"]]