public final class Loader extends Object implements LoaderErrorThrower
Loader.Loadables.| Modifier and Type | Class and Description |
|---|---|
static interface |
Loader.Callback<T extends Loader.Loadable>
A callback to be notified of
Loader events. |
static interface |
Loader.Loadable
An object that can be loaded using a
Loader. |
static interface |
Loader.ReleaseCallback
A callback to be notified when a
Loader has finished being released. |
static class |
Loader.UnexpectedLoaderException
Thrown when an unexpected exception or error is encountered during loading.
|
LoaderErrorThrower.Dummy| Modifier and Type | Field and Description |
|---|---|
static int |
DONT_RETRY |
static int |
DONT_RETRY_FATAL |
static int |
RETRY |
static int |
RETRY_RESET_ERROR_COUNT |
| Modifier and Type | Method and Description |
|---|---|
void |
cancelLoading()
Cancels the current load.
|
boolean |
isLoading()
Returns whether the
Loader is currently loading a Loader.Loadable. |
void |
maybeThrowError()
Throws a fatal error, or a non-fatal error if loading is currently backed off and the current
Loader.Loadable has incurred a number of errors greater than the Loaders default
minimum number of retries. |
void |
maybeThrowError(int minRetryCount)
Throws a fatal error, or a non-fatal error if loading is currently backed off and the current
Loader.Loadable has incurred a number of errors greater than the specified minimum number
of retries. |
void |
release()
Releases the
Loader. |
boolean |
release(Loader.ReleaseCallback callback)
Releases the
Loader. |
<T extends Loader.Loadable> |
startLoading(T loadable,
Loader.Callback<T> callback,
int defaultMinRetryCount)
Starts loading a
Loader.Loadable. |
public static final int RETRY
public static final int RETRY_RESET_ERROR_COUNT
public static final int DONT_RETRY
public static final int DONT_RETRY_FATAL
public Loader(String threadName)
threadName - A name for the loader's thread.public <T extends Loader.Loadable> long startLoading(T loadable, Loader.Callback<T> callback, int defaultMinRetryCount)
Loader.Loadable.
The calling thread must be a Looper thread, which is the thread on which the
Loader.Callback will be called.
T - The type of the loadable.loadable - The Loader.Loadable to load.callback - A callback to be called when the load ends.defaultMinRetryCount - The minimum number of times the load must be retried before
maybeThrowError() will propagate an error.SystemClock.elapsedRealtime() when the load started.IllegalStateException - If the calling thread does not have an associated Looper.public boolean isLoading()
Loader is currently loading a Loader.Loadable.public void cancelLoading()
public void release()
public boolean release(Loader.ReleaseCallback callback)
callback - A callback to be called when the release ends. Will be called synchronously
from this method if no load is in progress, or asynchronously once the load has been
canceled otherwise. May be null.callback was called synchronously. False if it will be called
asynchronously or if callback is null.public void maybeThrowError()
throws IOException
LoaderErrorThrowerLoader.Loadable has incurred a number of errors greater than the Loaders default
minimum number of retries. Else does nothing.maybeThrowError in interface LoaderErrorThrowerIOException - The error.public void maybeThrowError(int minRetryCount)
throws IOException
LoaderErrorThrowerLoader.Loadable has incurred a number of errors greater than the specified minimum number
of retries. Else does nothing.maybeThrowError in interface LoaderErrorThrowerminRetryCount - A minimum retry count that must be exceeded for a non-fatal error to be
thrown. Should be non-negative.IOException - The error.