public
abstract
class
AsyncTaskLoader
extends Loader<D>
| java.lang.Object | ||
| ↳ | android.support.v4.content.Loader<D> | |
| ↳ | android.support.v4.content.AsyncTaskLoader<D> | |
|
|
Static library support version of the framework's 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.
Public constructors | |
|---|---|
AsyncTaskLoader(Context context)
|
|
Public methods | |
|---|---|
void
|
cancelLoadInBackground()
Called on the main thread to abort a load in progress. |
void
|
dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args)
Print the Loader's state into the given stream. |
boolean
|
isLoadInBackgroundCanceled()
Returns true if the current invocation of |
abstract
D
|
loadInBackground()
Called on a worker thread to perform the actual load and to return the result of the load operation. |
void
|
onCanceled(D data)
Called if the task was canceled before it was completed. |
void
|
setUpdateThrottle(long delayMS)
Set amount to throttle updates by. |
Protected methods | |
|---|---|
boolean
|
onCancelLoad()
Subclasses must implement this to take care of requests to |
void
|
onForceLoad()
Subclasses must implement this to take care of requests to |
D
|
onLoadInBackground()
Calls |
android.support.v4.content.Loader
void
abandon()
This function will normally be called for you automatically by
LoaderManager when restarting a Loader.
boolean
cancelLoad()
Attempt to cancel the current load task.
void
commitContentChanged()
Commit that you have actually fully processed a content change that
was returned by takeContentChanged().
String
dataToString(D data)
For debugging, converts an instance of the Loader's data class to a string that can be printed.
void
deliverCancellation()
Informs the registered Loader.OnLoadCanceledListener that the load has been canceled.
void
deliverResult(D data)
Sends the result of the load to the registered listener.
void
dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args)
Print the Loader's state into the given stream.
void
forceLoad()
Force an asynchronous load.
Context
getContext()
int
getId()
boolean
isAbandoned()
Return whether this loader has been abandoned.
boolean
isReset()
Return whether this load has been reset.
boolean
isStarted()
Return whether this load has been started.
void
onAbandon()
Subclasses implement this to take care of being abandoned.
boolean
onCancelLoad()
Subclasses must implement this to take care of requests to cancelLoad().
void
onContentChanged()
Called when Loader.ForceLoadContentObserver detects a change.
void
onForceLoad()
Subclasses must implement this to take care of requests to forceLoad().
void
onReset()
Subclasses must implement this to take care of resetting their loader,
as per reset().
void
onStartLoading()
Subclasses must implement this to take care of loading their data,
as per startLoading().
void
onStopLoading()
Subclasses must implement this to take care of stopping their loader,
as per stopLoading().
void
registerListener(int id, OnLoadCompleteListener<D> listener)
Registers a class that will receive callbacks when a load is complete.
void
registerOnLoadCanceledListener(OnLoadCanceledListener<D> listener)
Registers a listener that will receive callbacks when a load is canceled.
void
reset()
This function will normally be called for you automatically by
LoaderManager when destroying a Loader.
void
rollbackContentChanged()
Report that you have abandoned the processing of a content change that
was returned by takeContentChanged() and would like to rollback
to the state where there is again a pending content change.
final
void
startLoading()
This function will normally be called for you automatically by
LoaderManager when the associated fragment/activity
is being started.
void
stopLoading()
This function will normally be called for you automatically by
LoaderManager when the associated fragment/activity
is being stopped.
boolean
takeContentChanged()
Take the current flag indicating whether the loader's content had changed while it was stopped.
String
toString()
void
unregisterListener(OnLoadCompleteListener<D> listener)
Remove a listener that was previously added with registerListener(int, Loader.OnLoadCompleteListener).
void
unregisterOnLoadCanceledListener(OnLoadCanceledListener<D> listener)
Unregisters a listener that was previously added with
registerOnLoadCanceledListener(Loader.OnLoadCanceledListener).
java.lang.Object
AsyncTaskLoader (Context context)
| Parameters | |
|---|---|
context |
Context |
void cancelLoadInBackground ()
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:
void dump (String prefix,
FileDescriptor fd,
PrintWriter writer,
String[] args)Print the Loader's state into the given stream.
| 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 |
String: Additional arguments to the dump request.
|
boolean isLoadInBackgroundCanceled ()
Returns true if the current invocation of loadInBackground() is being canceled.
| Returns | |
|---|---|
boolean |
True if the current invocation of loadInBackground() is being canceled. |
See also:
D loadInBackground ()
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(D) on
the UI thread. If implementations need to process the results on the UI thread
they may override deliverResult(D) 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(D) to perform post-cancellation cleanup and to dispose of the
result object, if any.
| Returns | |
|---|---|
D |
The result of the load operation. |
| Throws | |
|---|---|
OperationCanceledException |
if the load is canceled during execution. |
void onCanceled (D data)
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.
|
void setUpdateThrottle (long delayMS)
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.
|
boolean onCancelLoad ()
Subclasses must implement this to take care of requests to cancelLoad().
This will always be called from the process's main thread.
| Returns | |
|---|---|
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 Loader.OnLoadCanceledListener will be called
when the task completes.
|
void onForceLoad ()
Subclasses must implement this to take care of requests to forceLoad().
This will always be called from the process's main thread.
D onLoadInBackground ()
Calls loadInBackground().
This method is reserved for use by the loader framework.
Subclasses should override loadInBackground() instead of this method.
| Returns | |
|---|---|
D |
The result of the load operation. |
| Throws | |
|---|---|
OperationCanceledException |
if the load is canceled during execution. |
See also:
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.