Known Direct Subclasses |
A controllable Task that has a synchronized state machine.
Nested Class Summary
interface | StorageTask.ProvideError | An object that returns an exception. | |
class | StorageTask.SnapshotBase | Base class for state. |
Field Summary
protected final Object | syncObject |
Protected Constructor Summary
Public Method Summary
StorageTask<ResultT> |
addOnCanceledListener(OnCanceledListener
listener)
Adds a listener that is called if the Task is canceled.
|
StorageTask<ResultT> |
addOnCanceledListener(Executor
executor,
OnCanceledListener listener)
Adds a listener that is called if the Task is canceled.
|
StorageTask<ResultT> |
addOnCanceledListener(Activity
activity,
OnCanceledListener listener)
Adds an Activity-scoped listener that is called if the Task is canceled.
|
StorageTask<ResultT> |
addOnCompleteListener(Activity
activity,
OnCompleteListener<ResultT> listener)
Adds a listener that is called when the Task succeeds or fails.
|
StorageTask<ResultT> |
addOnCompleteListener(OnCompleteListener<ResultT>
listener)
Adds a listener that is called when the Task succeeds or fails.
|
StorageTask<ResultT> |
addOnCompleteListener(Executor
executor,
OnCompleteListener<ResultT> listener)
Adds a listener that is called when the Task succeeds or fails.
|
StorageTask<ResultT> |
addOnFailureListener(Activity
activity,
OnFailureListener listener)
Adds a listener that is called if the Task fails.
|
StorageTask<ResultT> | |
StorageTask<ResultT> |
addOnFailureListener(Executor
executor,
OnFailureListener listener)
Adds a listener that is called if the Task fails.
|
StorageTask<ResultT> |
addOnPausedListener(Executor
executor, OnPausedListener<? super ResultT>
listener)
Adds a listener that is called when the Task becomes paused.
|
StorageTask<ResultT> |
addOnPausedListener(OnPausedListener<? super ResultT>
listener)
Adds a listener that is called when the Task becomes paused.
|
StorageTask<ResultT> |
addOnPausedListener(Activity
activity, OnPausedListener<? super ResultT>
listener)
Adds a listener that is called when the Task becomes paused.
|
StorageTask<ResultT> |
addOnProgressListener(OnProgressListener<? super ResultT>
listener)
Adds a listener that is called periodically while the ControllableTask
executes.
|
StorageTask<ResultT> |
addOnProgressListener(Activity
activity, OnProgressListener<? super ResultT>
listener)
Adds a listener that is called periodically while the ControllableTask
executes.
|
StorageTask<ResultT> |
addOnProgressListener(Executor
executor, OnProgressListener<? super ResultT>
listener)
Adds a listener that is called periodically while the ControllableTask
executes.
|
StorageTask<ResultT> |
addOnSuccessListener(OnSuccessListener<? super ResultT>
listener)
Adds a listener that is called if the Task completes successfully.
|
StorageTask<ResultT> |
addOnSuccessListener(Executor
executor,
OnSuccessListener<? super ResultT> listener)
Adds a listener that is called if the Task completes successfully.
|
StorageTask<ResultT> |
addOnSuccessListener(Activity
activity,
OnSuccessListener<? super ResultT> listener)
Adds a listener that is called if the Task completes successfully.
|
boolean |
cancel()
Attempts to cancel the task.
|
<ContinuationResultT> Task<ContinuationResultT> |
continueWith(Continuation<ResultT, ContinuationResultT>
continuation)
Returns a new Task that will be completed with the result of applying the
specified Continuation to this Task.
|
<ContinuationResultT> Task<ContinuationResultT> |
continueWith(Executor
executor,
Continuation<ResultT, ContinuationResultT> continuation)
Returns a new Task that will be completed with the result of applying the
specified Continuation to this Task.
|
<ContinuationResultT> Task<ContinuationResultT> |
continueWithTask(Executor
executor,
Continuation<ResultT, Task<ContinuationResultT>>
continuation)
Returns a new Task that will be completed with the result of applying the
specified Continuation to this Task.
|
<ContinuationResultT> Task<ContinuationResultT> |
continueWithTask(Continuation<ResultT, Task<ContinuationResultT>>
continuation)
Returns a new Task that will be completed with the result of applying the
specified Continuation to this Task.
|
Exception |
getException()
Returns the exception that caused the Task to fail.
|
ResultT |
getResult()
Gets the result of the Task, if it has already completed.
|
<X extends Throwable> ResultT | |
ResultT |
getSnapshot()
Returns the current state of the task.
|
boolean |
isCanceled()
Returns
true if the task has been canceled.
|
boolean |
isComplete()
Returns
true if the Task is complete; false
otherwise.
|
boolean |
isInProgress()
Returns
true if the task is currently running.
|
boolean |
isPaused()
Returns
true if the task has been paused.
|
boolean |
isSuccessful()
Returns
true if the Task has completed successfully;
false otherwise.
|
<ContinuationResultT> Task<ContinuationResultT> |
onSuccessTask(SuccessContinuation<ResultT, ContinuationResultT>
continuation)
Returns a new Task that will be completed with the result of applying the
specified SuccessContinuation to this Task when this Task completes
successfully.
|
<ContinuationResultT> Task<ContinuationResultT> |
onSuccessTask(Executor
executor,
SuccessContinuation<ResultT, ContinuationResultT> continuation)
Returns a new Task that will be completed with the result of applying the
specified SuccessContinuation to this Task when this Task completes
successfully.
|
boolean |
pause()
Attempts to pause the task.
|
StorageTask<ResultT> | |
StorageTask<ResultT> | |
StorageTask<ResultT> | |
StorageTask<ResultT> | |
StorageTask<ResultT> | |
StorageTask<ResultT> | |
boolean |
resume()
Attempts to resume a paused task.
|
Protected Method Summary
void | |
void | |
void |
onPaused()
|
void | |
void |
onQueued()
|
void |
Inherited Method Summary
Fields
protected final Object syncObject
Protected Constructors
Public Methods
public StorageTask<ResultT> addOnCanceledListener (OnCanceledListener listener)
Adds a listener that is called if the Task is canceled.
The listener will be called on main application thread. If the Task has already been canceled, a call to the listener will be immediately scheduled. If multiple listeners are added, they will be called in the order in which they were added.
Returns
- this Task
public StorageTask<ResultT> addOnCanceledListener (Executor executor, OnCanceledListener listener)
Adds a listener that is called if the Task is canceled.
If the Task has already been canceled, a call to the listener will be immediately scheduled. If multiple listeners are added, they will be called in the order in which they were added.
Parameters
executor | the executor to use to call the listener |
---|---|
listener |
Returns
- this Task
public StorageTask<ResultT> addOnCanceledListener (Activity activity, OnCanceledListener listener)
Adds an Activity-scoped listener that is called if the Task is canceled.
The listener will be called on main application thread. If the Task has already been canceled, a call to the listener will be immediately scheduled. If multiple listeners are added, they will be called in the order in which they were added.
The listener will be automatically removed during onStop()
.
Returns
- this Task
public StorageTask<ResultT> addOnCompleteListener (Activity activity, OnCompleteListener<ResultT> listener)
Adds a listener that is called when the Task succeeds or fails.
If the task has already failed, a call to the listener will be immediately scheduled. If multiple listeners are added, they will be called in the order in which they were added.
Parameters
activity | When the supplied Activity
stops, this listener will automatically be removed. |
---|---|
listener |
Returns
- this Task
public StorageTask<ResultT> addOnCompleteListener (OnCompleteListener<ResultT> listener)
Adds a listener that is called when the Task succeeds or fails.
The listener will be called on main application thread. If the task has already failed, a call to the listener will be immediately scheduled. If multiple listeners are added, they will be called in the order in which they were added.
Returns
- this Task
public StorageTask<ResultT> addOnCompleteListener (Executor executor, OnCompleteListener<ResultT> listener)
Adds a listener that is called when the Task succeeds or fails.
If the task has already failed, a call to the listener will be immediately scheduled. If multiple listeners are added, they will be called in the order in which they were added.
Parameters
executor | the executor to use to call the listener |
---|---|
listener |
Returns
- this Task
public StorageTask<ResultT> addOnFailureListener (Activity activity, OnFailureListener listener)
Adds a listener that is called if the Task fails.
If the task has already failed, a call to the listener will be immediately scheduled. If multiple listeners are added, they will be called in the order in which they were added.
Parameters
activity | When the supplied Activity
stops, this listener will automatically be removed. |
---|---|
listener |
Returns
- this Task
public StorageTask<ResultT> addOnFailureListener (OnFailureListener listener)
Adds a listener that is called if the Task fails.
The listener will be called on main application thread. If the task has already failed, a call to the listener will be immediately scheduled. If multiple listeners are added, they will be called in the order in which they were added.
Returns
- this Task
public StorageTask<ResultT> addOnFailureListener (Executor executor, OnFailureListener listener)
Adds a listener that is called if the Task fails.
If the task has already failed, a call to the listener will be immediately scheduled. If multiple listeners are added, they will be called in the order in which they were added.
Parameters
executor | the executor to use to call the listener |
---|---|
listener |
Returns
- this Task
public StorageTask<ResultT> addOnPausedListener (Executor executor, OnPausedListener<? super ResultT> listener)
Adds a listener that is called when the Task becomes paused.
Parameters
executor | the executor to use to call the listener |
---|---|
listener |
Returns
- this Task
public StorageTask<ResultT> addOnPausedListener (OnPausedListener<? super ResultT> listener)
Adds a listener that is called when the Task becomes paused.
Returns
- this Task
public StorageTask<ResultT> addOnPausedListener (Activity activity, OnPausedListener<? super ResultT> listener)
Adds a listener that is called when the Task becomes paused.
Parameters
activity | When the supplied Activity
stops, this listener will automatically be removed. |
---|---|
listener |
Returns
- this Task
public StorageTask<ResultT> addOnProgressListener (OnProgressListener<? super ResultT> listener)
Adds a listener that is called periodically while the ControllableTask executes.
Returns
- this Task
public StorageTask<ResultT> addOnProgressListener (Activity activity, OnProgressListener<? super ResultT> listener)
Adds a listener that is called periodically while the ControllableTask executes.
Parameters
activity | When the supplied Activity
stops, this listener will automatically be removed. |
---|---|
listener |
Returns
- this Task
public StorageTask<ResultT> addOnProgressListener (Executor executor, OnProgressListener<? super ResultT> listener)
Adds a listener that is called periodically while the ControllableTask executes.
Parameters
executor | the executor to use to call the listener |
---|---|
listener |
Returns
- this Task
public StorageTask<ResultT> addOnSuccessListener (OnSuccessListener<? super ResultT> listener)
Adds a listener that is called if the Task completes successfully. The listener will be called on the main application thread. If the task has already completed successfully, a call to the listener will be immediately scheduled. If multiple listeners are added, they will be called in the order in which they were added.
Returns
- this Task
public StorageTask<ResultT> addOnSuccessListener (Executor executor, OnSuccessListener<? super ResultT> listener)
Adds a listener that is called if the Task completes successfully.
If multiple listeners are added, they will be called in the order in which they were added. If the task has already completed successfully, a call to the listener will be immediately scheduled.
Parameters
executor | the executor to use to call the listener |
---|---|
listener |
Returns
- this Task
public StorageTask<ResultT> addOnSuccessListener (Activity activity, OnSuccessListener<? super ResultT> listener)
Adds a listener that is called if the Task completes successfully.
If multiple listeners are added, they will be called in the order in which they were added. If the task has already completed successfully, a call to the listener will be immediately scheduled.
Parameters
activity | When the supplied Activity
stops, this listener will automatically be removed. |
---|---|
listener |
Returns
- this Task
public boolean cancel ()
Attempts to cancel the task. A canceled task cannot be resumed later.
Returns
true
if this task is successfully being canceled.
public Task<ContinuationResultT> continueWith (Continuation<ResultT, ContinuationResultT> continuation)
Returns a new Task that will be completed with the result of applying the specified Continuation to this Task.
The Continuation will be called on the main application thread.
See Also
public Task<ContinuationResultT> continueWith (Executor executor, Continuation<ResultT, ContinuationResultT> continuation)
Returns a new Task that will be completed with the result of applying the specified Continuation to this Task.
Parameters
executor | the executor to use to call the Continuation |
---|---|
continuation |
See Also
public Task<ContinuationResultT> continueWithTask (Executor executor, Continuation<ResultT, Task<ContinuationResultT>> continuation)
Returns a new Task that will be completed with the result of applying the specified Continuation to this Task.
Parameters
executor | the executor to use to call the Continuation |
---|---|
continuation |
See Also
public Task<ContinuationResultT> continueWithTask (Continuation<ResultT, Task<ContinuationResultT>> continuation)
Returns a new Task that will be completed with the result of applying the specified Continuation to this Task.
The Continuation will be called on the main application thread.
See Also
public Exception getException ()
Returns the exception that caused the Task to fail. Returns null
if the
Task is not yet complete, or completed successfully.
public ResultT getResult ()
Gets the result of the Task, if it has already completed.
Throws
IllegalStateException | if the Task is not yet complete |
---|---|
RuntimeExecutionException | if the Task failed with an exception |
public ResultT getResult (Class<X> exceptionType)
Gets the result of the Task, if it has already completed.
Throws
IllegalStateException | if the Task is not yet complete |
---|---|
if the Task failed with an exception of type X | |
RuntimeExecutionException | if the Task failed with an exception that was not of type X |
Throwable |
public ResultT getSnapshot ()
Returns the current state of the task. This method will return state at any point of the tasks execution and may not be the final result..
public boolean isCanceled ()
Returns true
if the task has been canceled.
Returns
- true if the task has been canceled.
public boolean isComplete ()
Returns true
if the Task is complete; false
otherwise.
public boolean isInProgress ()
Returns true
if the task is currently running.
Returns
- true if the task is currently running.
public boolean isPaused ()
Returns true
if the task has been paused.
Returns
- true if the task has been paused.
public boolean isSuccessful ()
Returns true
if the Task has completed successfully; false
otherwise.
public Task<ContinuationResultT> onSuccessTask (SuccessContinuation<ResultT, ContinuationResultT> continuation)
Returns a new Task that will be completed with the result of applying the specified SuccessContinuation to this Task when this Task completes successfully. If the previous Task fails, the onSuccessTask completion will be skipped and failure listeners will be invoked.
The SuccessContinuation will be called on the main application thread.
If the previous Task is canceled, the returned Task will also be canceled and the SuccessContinuation would not execute.
public Task<ContinuationResultT> onSuccessTask (Executor executor, SuccessContinuation<ResultT, ContinuationResultT> continuation)
Returns a new Task that will be completed with the result of applying the specified SuccessContinuation to this Task when this Task completes successfully. If the previous Task fails, the onSuccessTask completion will be skipped and failure listeners will be invoked.
If the previous Task is canceled, the returned Task will also be canceled and the SuccessContinuation would not execute.
Parameters
executor | the executor to use to call the SuccessContinuation |
---|---|
continuation |
public boolean pause ()
Attempts to pause the task. A paused task can later be resumed.
Returns
true
if this task is successfully being paused. Note that a task may not be immediately paused if it was executing another action and can still fail or complete.
public StorageTask<ResultT> removeOnCanceledListener (OnCanceledListener listener)
Removes a listener.
public StorageTask<ResultT> removeOnCompleteListener (OnCompleteListener<ResultT> listener)
Removes a listener.
public StorageTask<ResultT> removeOnFailureListener (OnFailureListener listener)
Removes a listener.
public StorageTask<ResultT> removeOnPausedListener (OnPausedListener<? super ResultT> listener)
Removes a listener.
public StorageTask<ResultT> removeOnProgressListener (OnProgressListener<? super ResultT> listener)
Removes a listener.
public StorageTask<ResultT> removeOnSuccessListener (OnSuccessListener<? super ResultT> listener)
Removes a listener.
public boolean resume ()
Attempts to resume a paused task.
Returns
true
if the task is successfully resumed.false
if the task has an unrecoverable error or has entered another state that precludes resume.