AsyncTaskLoader
abstract classAsyncTaskLoader<D : Any!> : Loader<D>
kotlin.Any | ||
↳ | android.content.Loader<D> | |
↳ | android.content.AsyncTaskLoader |
Abstract Loader that provides an AsyncTask
to do the work. See Loader
and android.app.LoaderManager
for more details.
Here is an example implementation of an AsyncTaskLoader subclass that loads the currently installed applications from the package manager. This implementation takes care of retrieving the application labels and sorting its result set from them, monitoring for changes to the installed applications, and rebuilding the list when a change in configuration requires this (such as a locale change).
An example implementation of a fragment that uses the above loader to show the currently installed applications in a list is below.
Summary
Public constructors | |
---|---|
AsyncTaskLoader(context: Context!) |
Public methods | |
---|---|
open Unit |
Called on the main thread to abort a load in progress. |
open Unit |
dump(prefix: String!, fd: FileDescriptor!, writer: PrintWriter!, args: Array<String!>!) |
open Boolean |
Returns true if the current invocation of |
abstract D |
Called on a worker thread to perform the actual load and to return the result of the load operation. |
open Unit |
onCanceled(data: D) Called if the task was canceled before it was completed. |
open Unit |
setUpdateThrottle(delayMS: Long) Set amount to throttle updates by. |
Protected methods | |
---|---|
open Boolean | |
open Unit | |
open D |
Calls |
Inherited functions | |
---|---|
Public constructors
Public methods
cancelLoadInBackground
open funcancelLoadInBackground(): Unit
Deprecated: Deprecated in Java.
Called on the main thread to abort a load in progress. Override this method to abort the current invocation of loadInBackground
that is running in the background on a worker thread. This method should do nothing if loadInBackground
has not started running or if it has already finished.
See Also
dump
open fundump(
prefix: String!,
fd: FileDescriptor!,
writer: PrintWriter!,
args: Array<String!>!
): Unit
Deprecated: Deprecated in Java.
Parameters | |
---|---|
prefix |
String!: Text to print at the front of each line. |
fd |
FileDescriptor!: The raw file descriptor that the dump is being sent to. |
writer |
PrintWriter!: A PrintWriter to which the dump is to be set. |
args |
Array<String!>!: Additional arguments to the dump request. |
isLoadInBackgroundCanceled
open funisLoadInBackgroundCanceled(): Boolean
Deprecated: Deprecated in Java.
Returns true if the current invocation of loadInBackground
is being canceled.
Return | |
---|---|
Boolean |
True if the current invocation of loadInBackground is being canceled. |
See Also
loadInBackground
abstract funloadInBackground(): D
Deprecated: Deprecated in Java.
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 deliverResult
on the UI thread. If implementations need to process the results on the UI thread they may override deliverResult
and do so there. To support cancellation, this method should periodically check the value of isLoadInBackgroundCanceled
and terminate when it returns true. Subclasses may also override cancelLoadInBackground
to interrupt the load directly instead of polling isLoadInBackgroundCanceled
. When the load is canceled, this method may either return normally or throw OperationCanceledException
. In either case, the Loader
will call onCanceled
to perform post-cancellation cleanup and to dispose of the result object, if any.
Return | |
---|---|
D |
The result of the load operation. |
Exceptions | |
---|---|
android.os.OperationCanceledException |
if the load is canceled during execution. |
onCanceled
open funonCanceled(data: D): Unit
Deprecated: Deprecated in Java.
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 | |
---|---|
data |
D: The value that was returned by loadInBackground , or null if the task threw OperationCanceledException . |
setUpdateThrottle
open funsetUpdateThrottle(delayMS: Long): Unit
Deprecated: Deprecated in Java.
Set amount to throttle updates by. This is the minimum time from when the last loadInBackground()
call has completed until a new load is scheduled.
Parameters | |
---|---|
delayMS |
Long: Amount of delay, in milliseconds. |
Protected methods
onCancelLoad
protected open funonCancelLoad(): Boolean
Deprecated: Deprecated in Java.
Return | |
---|---|
Boolean |
Returns false if the task could not be canceled, typically because it has already completed normally, or because startLoading() hasn't been called; returns true otherwise. When true is returned, the task is still running and the OnLoadCanceledListener will be called when the task completes. |
onForceLoad
protected open funonForceLoad(): Unit
Deprecated: Deprecated in Java.
onLoadInBackground
protected open funonLoadInBackground(): D
Deprecated: Deprecated in Java.
Calls loadInBackground()
. This method is reserved for use by the loader framework. Subclasses should override loadInBackground
instead of this method.
Return | |
---|---|
D |
The result of the load operation. |
Exceptions | |
---|---|
android.os.OperationCanceledException |
if the load is canceled during execution. |
See Also