Task

public abstract classTask<TResult>

Represents an asynchronous operation.

Parameters
<TResult>

the type of the result of the operation

See also
Tasks

Summary

Public constructors

Public methods

@NonNullTask<TResult>

Adds a listener that is called if the Task is canceled.

@NonNullTask<TResult>

Adds an Activity-scoped listener that is called if the Task is canceled.

@NonNullTask<TResult>

Adds a listener that is called if the Task is canceled.

@NonNullTask<TResult>

Adds a listener that is called when the Task completes.

@NonNullTask<TResult>

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

@NonNullTask<TResult>

Adds a listener that is called when the Task completes.

abstract @NonNullTask<TResult>

Adds a listener that is called if the Task fails.

abstract @NonNullTask<TResult>

Adds an Activity-scoped listener that is called if the Task fails.

abstract @NonNullTask<TResult>

Adds a listener that is called if the Task fails.

abstract @NonNullTask<TResult>

Adds a listener that is called if the Task completes successfully.

abstract @NonNullTask<TResult>

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

abstract @NonNullTask<TResult>

Adds a listener that is called if the Task completes successfully.

@NonNullTask<TContinuationResult>
<TContinuationResult>continueWith(
@NonNullContinuation<TResult, TContinuationResult> continuation
)

Returns a new Task that will be completed with the result of applying the specified Continuation to this Task.

@NonNullTask<TContinuationResult>
<TContinuationResult>continueWith(
@NonNullExecutorexecutor,
@NonNullContinuation<TResult, TContinuationResult> continuation
)

Returns a new Task that will be completed with the result of applying the specified Continuation to this Task.

@NonNullTask<TContinuationResult>
<TContinuationResult>continueWithTask(
@NonNullContinuation<TResult,Task<TContinuationResult>> continuation
)

Returns a new Task that will be completed with the result of applying the specified Continuation to this Task.

@NonNullTask<TContinuationResult>
<TContinuationResult>continueWithTask(
@NonNullExecutorexecutor,
@NonNullContinuation<TResult,Task<TContinuationResult>> continuation
)

Returns a new Task that will be completed with the result of applying the specified Continuation to this Task.

abstract @NullableException

Returns the exception that caused the Task to fail.

abstract TResult

Gets the result of the Task, if it has already completed.

abstract TResult
<X extendsThrowable>getResult(@NonNullClass<X> exceptionType)

Gets the result of the Task, if it has already completed.

abstract boolean

Returnstrueif the Task is canceled;falseotherwise.

abstract boolean

Returnstrueif the Task is complete;falseotherwise.

abstract boolean

Returnstrueif the Task has completed successfully;falseotherwise.

@NonNullTask<TContinuationResult>
<TContinuationResult>onSuccessTask(
@NonNullSuccessContinuation<TResult, TContinuationResult> successContinuation
)

Returns a new Task that will be completed with the result of applying the specified SuccessContinuation to this Task when this Task completes successfully.

@NonNullTask<TContinuationResult>
<TContinuationResult>onSuccessTask(
@NonNullExecutorexecutor,
@NonNullSuccessContinuation<TResult, TContinuationResult> successContinuation
)

Returns a new Task that will be completed with the result of applying the specified SuccessContinuation to this Task when this Task completes successfully.

Public constructors

Task

publicTask()

Public methods

addOnCanceledListener

@CanIgnoreReturnValue
public @NonNullTask<TResult>addOnCanceledListener(@NonNullOnCanceledListenerlistener)

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
@NonNullTask<TResult>

this Task

addOnCanceledListener

@CanIgnoreReturnValue
public @NonNullTask<TResult>addOnCanceledListener(
@NonNullActivityactivity,
@NonNullOnCanceledListenerlistener
)

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 duringonStop.

Returns
@NonNullTask<TResult>

this Task

addOnCanceledListener

@CanIgnoreReturnValue
public @NonNullTask<TResult>addOnCanceledListener(
@NonNullExecutorexecutor,
@NonNullOnCanceledListenerlistener
)

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
@NonNullExecutorexecutor

the executor to use to call the listener

Returns
@NonNullTask<TResult>

this Task

addOnCompleteListener

@CanIgnoreReturnValue
public @NonNullTask<TResult>addOnCompleteListener(@NonNullOnCompleteListener<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. A Task is considered complete if it succeeds, fails, or is canceled. If multiple listeners are added, they will be called in the order in which they were added.

Returns
@NonNullTask<TResult>

this Task

addOnCompleteListener

@CanIgnoreReturnValue
public @NonNullTask<TResult>addOnCompleteListener(
@NonNullActivityactivity,
@NonNullOnCompleteListener<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. A Task is considered complete if it succeeds, fails, or is canceled. If multiple listeners are added, they will be called in the order in which they were added.

The listener will be automatically removed duringonStop.

Returns
@NonNullTask<TResult>

this Task

addOnCompleteListener

@CanIgnoreReturnValue
public @NonNullTask<TResult>addOnCompleteListener(
@NonNullExecutorexecutor,
@NonNullOnCompleteListener<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. A Task is considered complete if it succeeds, fails, or is canceled. If multiple listeners are added, they will be called in the order in which they were added.

Parameters
@NonNullExecutorexecutor

the executor to use to call the listener

Returns
@NonNullTask<TResult>

this Task

addOnFailureListener

@CanIgnoreReturnValue
public abstract @NonNullTask<TResult>addOnFailureListener(@NonNullOnFailureListenerlistener)

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.

A canceled Task is not a failure Task. This listener will not trigger if the Task is canceled.

Returns
@NonNullTask<TResult>

this Task

addOnFailureListener

@CanIgnoreReturnValue
public abstract @NonNullTask<TResult>addOnFailureListener(
@NonNullActivityactivity,
@NonNullOnFailureListenerlistener
)

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.

A canceled Task is not a failure Task. This listener will not trigger if the Task is canceled.

The listener will be automatically removed duringonStop.

Returns
@NonNullTask<TResult>

this Task

addOnFailureListener

@CanIgnoreReturnValue
public abstract @NonNullTask<TResult>addOnFailureListener(
@NonNullExecutorexecutor,
@NonNullOnFailureListenerlistener
)

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
@NonNullExecutorexecutor

the executor to use to call the listener

Returns
@NonNullTask<TResult>

this Task

addOnSuccessListener

@CanIgnoreReturnValue
public abstract @NonNullTask<TResult>addOnSuccessListener(@NonNullOnSuccessListener<Object> 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
@NonNullTask<TResult>

this Task

addOnSuccessListener

@CanIgnoreReturnValue
public abstract @NonNullTask<TResult>addOnSuccessListener(
@NonNullActivityactivity,
@NonNullOnSuccessListener<Object> 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 duringonStop.

Returns
@NonNullTask<TResult>

this Task

addOnSuccessListener

@CanIgnoreReturnValue
public abstract @NonNullTask<TResult>addOnSuccessListener(
@NonNullExecutorexecutor,
@NonNullOnSuccessListener<Object> 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
@NonNullExecutorexecutor

the executor to use to call the listener

Returns
@NonNullTask<TResult>

this Task

continueWith

public @NonNullTask<TContinuationResult> <TContinuationResult>continueWith(
@NonNullContinuation<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.

If the previous Task is canceled, the returned Task will also be canceled and the Continuation would not execute.

See also
then

continueWith

public @NonNullTask<TContinuationResult> <TContinuationResult>continueWith(
@NonNullExecutorexecutor,
@NonNullContinuation<TResult, TContinuationResult> continuation
)

Returns a new Task that will be completed with the result of applying the specified Continuation to this Task.

If the previous Task is canceled, the returned Task will also be canceled and the Continuation would not execute.

Parameters
@NonNullExecutorexecutor

the executor to use to call the Continuation

See also
then

continueWithTask

public @NonNullTask<TContinuationResult> <TContinuationResult>continueWithTask(
@NonNullContinuation<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.

If the previous Task is canceled, the Continuation would still execute and task.isCanceled() is true can be observed in the Continuation.

See also
then

continueWithTask

public @NonNullTask<TContinuationResult> <TContinuationResult>continueWithTask(
@NonNullExecutorexecutor,
@NonNullContinuation<TResult,Task<TContinuationResult>> continuation
)

Returns a new Task that will be completed with the result of applying the specified Continuation to this Task.

If the previous Task is canceled, the Continuation would still execute and task.isCanceled() is true can be observed in the Continuation.

Parameters
@NonNullExecutorexecutor

the executor to use to call the Continuation

See also
then

getException

public abstract @NullableExceptiongetException()

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

getResult

public abstract TResultgetResult()

Gets the result of the Task, if it has already completed.

Throws
java.lang.IllegalStateException

if the Task is not yet complete

com.google.android.gms.tasks.RuntimeExecutionException

if the Task failed with an exception

getResult

public abstract TResult <X extendsThrowable>getResult(@NonNullClass<X> exceptionType)

Gets the result of the Task, if it has already completed.

Throws
java.lang.IllegalStateException

if the Task is not yet complete

X

if the Task failed with an exception of type X

com.google.android.gms.tasks.RuntimeExecutionException

if the Task failed with an exception that was not of type X

isCanceled

public abstract booleanisCanceled()

Returnstrueif the Task is canceled;falseotherwise.

isComplete

public abstract booleanisComplete()

Returnstrueif the Task is complete;falseotherwise.

isSuccessful

public abstract booleanisSuccessful()

Returnstrueif the Task has completed successfully;falseotherwise.

onSuccessTask

public @NonNullTask<TContinuationResult> <TContinuationResult>onSuccessTask(
@NonNullSuccessContinuation<TResult, TContinuationResult> successContinuation
)

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
then

onSuccessTask

public @NonNullTask<TContinuationResult> <TContinuationResult>onSuccessTask(
@NonNullExecutorexecutor,
@NonNullSuccessContinuation<TResult, TContinuationResult> successContinuation
)

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
@NonNullExecutorexecutor

the executor to use to call the SuccessContinuation

See also
then