Summary: Ctors | Methods | Inherited Methods | [Expand All]
public abstract class

# Task

extends Object

java.lang.Object
↳ | com.google.android.gms.tasks.Task<TResult>

Known Direct Subclasses CancellableTask<TState>
CancellableTask<TState> | Represents an asynchronous operation that can be canceled.

Known Indirect Subclasses ControllableTask<TState>, FileDownloadTask, StorageTask<TResult extends StorageTask.ProvideError>, StreamDownloadTask, UploadTask
ControllableTask<TState> | Represents an asynchronous operation that can be paused, resumed and canceled.
FileDownloadTask | A task that downloads bytes of a GCS blob to a specified File.
StorageTask<TResult extends StorageTask.ProvideError> | A controllable Task that has a synchronized state machine.
StreamDownloadTask | A task that downloads bytes of a GCS blob.
UploadTask | An controllable task that uploads and fires events for success, progress and failure.

## Class Overview

Represents an asynchronous operation.

## Summary

Public Constructors
| Task()

Public Methods
Task<TResult> | addOnCompleteListener(OnCompleteListener<TResult> listener) Adds a listener that is called when the Task completes.
Task<TResult> | addOnCompleteListener(Activity activity, OnCompleteListener<TResult> listener) Adds an Activity-scoped listener that is called when the Task completes.
Task<TResult> | addOnCompleteListener(Executor executor, OnCompleteListener<TResult> listener) Adds a listener that is called when the Task completes.
abstract Task<TResult> | addOnFailureListener(Activity activity, OnFailureListener listener) Adds an Activity-scoped listener that is called if the Task fails.
abstract Task<TResult> | addOnFailureListener(OnFailureListener listener) Adds a listener that is called if the Task fails.
abstract Task<TResult> | addOnFailureListener(Executor executor, OnFailureListener listener) Adds a listener that is called if the Task fails.
abstract Task<TResult> | addOnSuccessListener(Executor executor, OnSuccessListener<? super TResult> listener) Adds a listener that is called if the Task completes successfully.
abstract Task<TResult> | addOnSuccessListener(OnSuccessListener<? super TResult> listener) Adds a listener that is called if the Task completes successfully.
abstract Task<TResult> | addOnSuccessListener(Activity activity, OnSuccessListener<? super TResult> listener) Adds an Activity-scoped listener that is called if the Task completes successfully.
<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(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(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.
abstract Exception | getException() Returns the exception that caused the Task to fail.
abstract TResult | getResult() Gets the result of the Task, if it has already completed.
abstract <X extends Throwable> TResult | getResult(Class<X> exceptionType) Gets the result of the Task, if it has already completed.
abstract boolean | isComplete() Returns `true` if the Task is complete; `false` otherwise.
abstract boolean | isSuccessful() Returns `true` if the Task has completed successfully; `false` otherwise.

[Expand] Inherited Methods
From class java.lang.Object
Object | clone()
boolean | equals(Object arg0)
void | finalize()
final Class<?> | getClass()
int | hashCode()
final void | notify()
final void | notifyAll()
String | toString()
final void | wait(long arg0, int arg1)
final void | wait(long arg0)
final void | wait()

## Public Constructors

#### public Task ()

## Public Methods

#### public Task<TResult> addOnCompleteListener (OnCompleteListener<TResult> listener)

Adds a listener that is called when the Task completes.

The listener will be called on main application thread. If the Task is already complete, 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 Task<TResult> addOnCompleteListener (Activity activity, OnCompleteListener<TResult> listener)

Adds an Activity-scoped listener that is called when the Task completes.

The listener will be called on main application thread. If the Task is already complete, 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 Task<TResult> addOnCompleteListener (Executor executor, OnCompleteListener<TResult> listener)

Adds a listener that is called when the Task completes.

If the Task is already complete, 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

##### Returns

- this Task

#### public abstract Task<TResult> addOnFailureListener (Activity activity, OnFailureListener listener)

Adds an Activity-scoped 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.

The listener will be automatically removed during `onStop()`.

##### Returns

- this Task

#### public abstract Task<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 abstract Task<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

##### Returns

- this Task

#### public abstract Task<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

##### Returns

- this Task

#### public abstract Task<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 abstract Task<TResult> addOnSuccessListener (Activity activity, OnSuccessListener<? super TResult> listener)

Adds an Activity-scoped 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.

The listener will be automatically removed during `onStop()`.

##### Returns

- this Task

#### 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

- `then(Task)`

#### 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

##### See Also

- `then(Task)`

#### 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

- `then(Task)`

#### 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

##### See Also

- `then(Task)`

#### public abstract Exception getException ()

Returns the exception that caused the Task to fail. Returns `null` if the Task is not yet complete, or completed successfully.

#### public abstract 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 abstract 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 abstract boolean isComplete ()

Returns `true` if the Task is complete; `false` otherwise.

#### public abstract boolean isSuccessful ()

Returns `true` if the Task has completed successfully; `false` otherwise.