StorageTask

public abstract class StorageTask extends ControllableTask<TResult extends StorageTask.ProvideError>
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 mSyncObject

Protected Constructor Summary

Public Method Summary

StorageTask<TResult>
addOnCanceledListener(OnCanceledListener listener)
Adds a listener that is called if the Task is canceled.
StorageTask<TResult>
addOnCanceledListener(Executor executor, OnCanceledListener listener)
Adds a listener that is called if the Task is canceled.
StorageTask<TResult>
addOnCanceledListener(Activity activity, OnCanceledListener listener)
Adds an Activity-scoped listener that is called if the Task is canceled.
StorageTask<TResult>
addOnCompleteListener(OnCompleteListener<TResult> listener)
Adds a listener that is called when the Task succeeds or fails.
StorageTask<TResult>
addOnCompleteListener(Activity activity, OnCompleteListener<TResult> listener)
Adds a listener that is called when the Task succeeds or fails.
StorageTask<TResult>
addOnCompleteListener(Executor executor, OnCompleteListener<TResult> listener)
Adds a listener that is called when the Task succeeds or fails.
StorageTask<TResult>
addOnFailureListener(Activity activity, OnFailureListener listener)
Adds a listener that is called if the Task fails.
StorageTask<TResult>
addOnFailureListener(OnFailureListener listener)
Adds a listener that is called if the Task fails.
StorageTask<TResult>
addOnFailureListener(Executor executor, OnFailureListener listener)
Adds a listener that is called if the Task fails.
StorageTask<TResult>
addOnPausedListener(Executor executor, OnPausedListener<? super TResult> listener)
Adds a listener that is called when the Task becomes paused.
StorageTask<TResult>
addOnPausedListener(Activity activity, OnPausedListener<? super TResult> listener)
Adds a listener that is called when the Task becomes paused.
StorageTask<TResult>
addOnPausedListener(OnPausedListener<? super TResult> listener)
Adds a listener that is called when the Task becomes paused.
StorageTask<TResult>
addOnProgressListener(Executor executor, OnProgressListener<? super TResult> listener)
Adds a listener that is called periodically while the ControllableTask executes.
StorageTask<TResult>
addOnProgressListener(OnProgressListener<? super TResult> listener)
Adds a listener that is called periodically while the ControllableTask executes.
StorageTask<TResult>
addOnProgressListener(Activity activity, OnProgressListener<? super TResult> listener)
Adds a listener that is called periodically while the ControllableTask executes.
StorageTask<TResult>
addOnSuccessListener(OnSuccessListener<? super TResult> listener)
Adds a listener that is called if the Task completes successfully.
StorageTask<TResult>
addOnSuccessListener(Activity activity, OnSuccessListener<? super TResult> listener)
Adds a listener that is called if the Task completes successfully.
StorageTask<TResult>
addOnSuccessListener(Executor executor, OnSuccessListener<? super TResult> listener)
Adds a listener that is called if the Task completes successfully.
boolean
cancel()
Attempts to cancel the task.
<TContinuationResult> Task<TContinuationResult>
continueWith(Continuation<TResult, TContinuationResult> continuation)
Returns a new Task that will be completed with the result of applying the specified Continuation to this Task.
<TContinuationResult> Task<TContinuationResult>
continueWith(Executor executor, Continuation<TResult, TContinuationResult> continuation)
Returns a new Task that will be completed with the result of applying the specified Continuation to this Task.
<TContinuationResult> Task<TContinuationResult>
continueWithTask(Executor executor, Continuation<TResult, Task<TContinuationResult>> continuation)
Returns a new Task that will be completed with the result of applying the specified Continuation to this Task.
<TContinuationResult> Task<TContinuationResult>
continueWithTask(Continuation<TResult, Task<TContinuationResult>> 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.
TResult
getResult()
Gets the result of the Task, if it has already completed.
<X extends Throwable> TResult
getResult(Class<X> exceptionType)
Gets the result of the Task, if it has already completed.
TResult
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.
<TContinuationResult> Task<TContinuationResult>
onSuccessTask(Executor executor, SuccessContinuation<TResult, TContinuationResult> 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.
<TContinuationResult> Task<TContinuationResult>
onSuccessTask(SuccessContinuation<TResult, TContinuationResult> 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<TResult>
removeOnCanceledListener(OnCanceledListener listener)
Removes a listener.
StorageTask<TResult>
removeOnCompleteListener(OnCompleteListener<TResult> listener)
Removes a listener.
StorageTask<TResult>
removeOnFailureListener(OnFailureListener listener)
Removes a listener.
StorageTask<TResult>
removeOnPausedListener(OnPausedListener<? super TResult> listener)
Removes a listener.
StorageTask<TResult>
removeOnProgressListener(OnProgressListener<? super TResult> listener)
Removes a listener.
StorageTask<TResult>
removeOnSuccessListener(OnSuccessListener<? super TResult> listener)
Removes a listener.
boolean
resume()
Attempts to resume a paused task.

Protected Method Summary

void
void
void
void
void
void

Inherited Method Summary

Fields

protected final Object mSyncObject

Protected Constructors

protected StorageTask ()

Public Methods

public StorageTask<TResult> 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<TResult> 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<TResult> 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<TResult> addOnCompleteListener (OnCompleteListener<TResult> 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<TResult> addOnCompleteListener (Activity activity, OnCompleteListener<TResult> 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<TResult> addOnCompleteListener (Executor executor, OnCompleteListener<TResult> 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<TResult> 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<TResult> 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<TResult> 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<TResult> addOnPausedListener (Executor executor, OnPausedListener<? super TResult> 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<TResult> addOnPausedListener (Activity activity, OnPausedListener<? super TResult> 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<TResult> addOnPausedListener (OnPausedListener<? super TResult> listener)

Adds a listener that is called when the Task becomes paused.

Returns
  • this Task

public StorageTask<TResult> addOnProgressListener (Executor executor, OnProgressListener<? super TResult> 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<TResult> addOnProgressListener (OnProgressListener<? super TResult> listener)

Adds a listener that is called periodically while the ControllableTask executes.

Returns
  • this Task

public StorageTask<TResult> addOnProgressListener (Activity activity, OnProgressListener<? super TResult> 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<TResult> addOnSuccessListener (OnSuccessListener<? super TResult> 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<TResult> addOnSuccessListener (Activity activity, OnSuccessListener<? super TResult> 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 StorageTask<TResult> addOnSuccessListener (Executor executor, OnSuccessListener<? super TResult> 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 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<TContinuationResult> continueWith (Continuation<TResult, TContinuationResult> 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<TContinuationResult> continueWith (Executor executor, Continuation<TResult, TContinuationResult> 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<TContinuationResult> continueWithTask (Executor executor, Continuation<TResult, Task<TContinuationResult>> 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<TContinuationResult> continueWithTask (Continuation<TResult, Task<TContinuationResult>> 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 TResult 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 TResult 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 TResult 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<TContinuationResult> onSuccessTask (Executor executor, SuccessContinuation<TResult, TContinuationResult> 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
See Also

public Task<TContinuationResult> onSuccessTask (SuccessContinuation<TResult, TContinuationResult> 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.

See Also

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<TResult> removeOnCanceledListener (OnCanceledListener listener)

Removes a listener.

public StorageTask<TResult> removeOnCompleteListener (OnCompleteListener<TResult> listener)

Removes a listener.

public StorageTask<TResult> removeOnFailureListener (OnFailureListener listener)

Removes a listener.

public StorageTask<TResult> removeOnPausedListener (OnPausedListener<? super TResult> listener)

Removes a listener.

public StorageTask<TResult> removeOnProgressListener (OnProgressListener<? super TResult> listener)

Removes a listener.

public StorageTask<TResult> removeOnSuccessListener (OnSuccessListener<? super TResult> 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.

Protected Methods

protected void onCanceled ()

protected void onFailure ()

protected void onPaused ()

protected void onProgress ()

protected void onQueued ()

protected void onSuccess ()

Send feedback about...

Need help? Visit our support page.