AsyncTaskLoader
abstract class AsyncTaskLoader<D : Any!> : Loader<D>
kotlin.Any | ||
↳ | androidx.loader.content.Loader<D> | |
↳ | androidx.loader.content.AsyncTaskLoader |
Static library support version of the framework's android.content.AsyncTaskLoader
. 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 |
|
---|---|
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(@Nullable 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 Executor | |
open Boolean | |
open Unit | |
open D? |
Calls |
Inherited functions |
|
---|---|
Public constructors
<init>
AsyncTaskLoader(@NonNull context: Context)
Public methods
cancelLoadInBackground
open fun cancelLoadInBackground(): Unit
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: Consider using LoaderManager#enableDebugLogging(boolean)
to understand the series of operations performed by LoaderManager.
Parameters | |
---|---|
prefix |
String!: Text to print at the front of each line. |
fd |
String!: The raw file descriptor that the dump is being sent to. |
writer |
String!: A PrintWriter to which the dump is to be set. |
args |
String!: Additional arguments to the dump request. |
isLoadInBackgroundCanceled
open fun isLoadInBackgroundCanceled(): Boolean
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
@Nullable abstract fun loadInBackground(): D?
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 | |
---|---|
OperationCanceledException |
if the load is canceled during execution. |
onCanceled
open fun onCanceled(@Nullable data: D?): Unit
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 fun setUpdateThrottle(delayMS: Long): Unit
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
getExecutor
@NonNull protected open fun getExecutor(): Executor
Returns the Executor
to use for this Loader
's AsyncTask
s. By default AsyncTask#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 Loader
's first AsyncTask
is run. It is up to the Loader
to shut down the Executor
at the appropriate place (e.g. in onAbandon()
) if necessary.
Return | |
---|---|
Executor: the Executor to use for this Loader 's AsyncTask s. |
onCancelLoad
protected open fun onCancelLoad(): Boolean
onForceLoad
protected open fun onForceLoad(): Unit
onLoadInBackground
@Nullable protected open fun onLoadInBackground(): D?
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 | |
---|---|
OperationCanceledException |
if the load is canceled during execution. |
See Also