public final class Loader extends java.lang.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 interface |
Loader.RetryAction
Actions that can be taken in response to a load error.
|
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 |
| Constructor and Description |
|---|
Loader(java.lang.String threadName) |
| 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. |
void |
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(java.lang.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.java.lang.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 void release(@Nullable
Loader.ReleaseCallback callback)
callback - An optional callback to be called on the loading thread once the loader has
been released.public void maybeThrowError()
throws java.io.IOException
LoaderErrorThrowerLoader.Loadable has incurred a number of errors greater than the Loaders default
minimum number of retries. Else does nothing.maybeThrowError in interface LoaderErrorThrowerjava.io.IOException - The error.public void maybeThrowError(int minRetryCount)
throws java.io.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.java.io.IOException - The error.