Task

abstract class Task<TResult>

Represents an asynchronous operation.

Parameters
<TResult>

the type of the result of the operation

See also
Tasks

Summary

Public constructors

Public functions

Task<TResult!>

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

Task<TResult!>

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

Task<TResult!>

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

Task<TResult!>

Adds a listener that is called when the Task completes.

Task<TResult!>
@CanIgnoreReturnValue
addOnCompleteListener(
    activity: Activity,
    listener: OnCompleteListener<TResult!>
)

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

Task<TResult!>
@CanIgnoreReturnValue
addOnCompleteListener(
    executor: Executor,
    listener: OnCompleteListener<TResult!>
)

Adds a listener that is called when the Task completes.

abstract Task<TResult!>

Adds a listener that is called if the Task fails.

abstract Task<TResult!>

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

abstract Task<TResult!>

Adds a listener that is called if the Task fails.

abstract Task<TResult!>

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

abstract Task<TResult!>

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

abstract Task<TResult!>

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

Task<TContinuationResult!>
<TContinuationResult> continueWith(
    continuation: Continuation<TResult!, TContinuationResult!>
)

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

Task<TContinuationResult!>
<TContinuationResult> continueWith(
    executor: Executor,
    continuation: Continuation<TResult!, TContinuationResult!>
)

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

Task<TContinuationResult!>
<TContinuationResult> continueWithTask(
    continuation: Continuation<TResult!, Task<TContinuationResult!>!>
)

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

Task<TContinuationResult!>
<TContinuationResult> continueWithTask(
    executor: Executor,
    continuation: Continuation<TResult!, Task<TContinuationResult!>!>
)

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

abstract Exception?

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 : Throwable?> getResult(exceptionType: Class<X!>)

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

abstract Boolean

Returns true if the Task is canceled; false otherwise.

abstract Boolean

Returns true if the Task is complete; false otherwise.

abstract Boolean

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

Task<TContinuationResult!>
<TContinuationResult> onSuccessTask(
    successContinuation: SuccessContinuation<TResult!, TContinuationResult!>
)

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

Task<TContinuationResult!>
<TContinuationResult> onSuccessTask(
    executor: Executor,
    successContinuation: SuccessContinuation<TResult!, TContinuationResult!>
)

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

Task()

Public functions

addOnCanceledListener

@CanIgnoreReturnValue
fun addOnCanceledListener(listener: OnCanceledListener): Task<TResult!>

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
Task<TResult!>

this Task

addOnCanceledListener

@CanIgnoreReturnValue
fun addOnCanceledListener(activity: Activity, listener: OnCanceledListener): Task<TResult!>

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
Task<TResult!>

this Task

addOnCanceledListener

@CanIgnoreReturnValue
fun addOnCanceledListener(executor: Executor, listener: OnCanceledListener): Task<TResult!>

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: Executor

the executor to use to call the listener

Returns
Task<TResult!>

this Task

addOnCompleteListener

@CanIgnoreReturnValue
fun addOnCompleteListener(listener: OnCompleteListener<TResult!>): Task<TResult!>

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
Task<TResult!>

this Task

addOnCompleteListener

@CanIgnoreReturnValue
fun addOnCompleteListener(
    activity: Activity,
    listener: OnCompleteListener<TResult!>
): Task<TResult!>

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 during onStop.

Returns
Task<TResult!>

this Task

addOnCompleteListener

@CanIgnoreReturnValue
fun addOnCompleteListener(
    executor: Executor,
    listener: OnCompleteListener<TResult!>
): Task<TResult!>

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
executor: Executor

the executor to use to call the listener

Returns
Task<TResult!>

this Task

addOnFailureListener

@CanIgnoreReturnValue
abstract fun addOnFailureListener(listener: OnFailureListener): Task<TResult!>

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
Task<TResult!>

this Task

addOnFailureListener

@CanIgnoreReturnValue
abstract fun addOnFailureListener(activity: Activity, listener: OnFailureListener): Task<TResult!>

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 during onStop.

Returns
Task<TResult!>

this Task

addOnFailureListener

@CanIgnoreReturnValue
abstract fun addOnFailureListener(executor: Executor, listener: OnFailureListener): Task<TResult!>

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: Executor

the executor to use to call the listener

Returns
Task<TResult!>

this Task

addOnSuccessListener

@CanIgnoreReturnValue
abstract fun addOnSuccessListener(listener: OnSuccessListener<Any!>): Task<TResult!>

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
Task<TResult!>

this Task

addOnSuccessListener

@CanIgnoreReturnValue
abstract fun addOnSuccessListener(
    activity: Activity,
    listener: OnSuccessListener<Any!>
): Task<TResult!>

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
Task<TResult!>

this Task

addOnSuccessListener

@CanIgnoreReturnValue
abstract fun addOnSuccessListener(
    executor: Executor,
    listener: OnSuccessListener<Any!>
): Task<TResult!>

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: Executor

the executor to use to call the listener

Returns
Task<TResult!>

this Task

continueWith

fun <TContinuationResult> continueWith(
    continuation: Continuation<TResult!, TContinuationResult!>
): Task<TContinuationResult!>

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

fun <TContinuationResult> continueWith(
    executor: Executor,
    continuation: Continuation<TResult!, TContinuationResult!>
): Task<TContinuationResult!>

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
executor: Executor

the executor to use to call the Continuation

See also
then

continueWithTask

fun <TContinuationResult> continueWithTask(
    continuation: Continuation<TResult!, Task<TContinuationResult!>!>
): Task<TContinuationResult!>

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

fun <TContinuationResult> continueWithTask(
    executor: Executor,
    continuation: Continuation<TResult!, Task<TContinuationResult!>!>
): Task<TContinuationResult!>

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
executor: Executor

the executor to use to call the Continuation

See also
then

getException

abstract fun getException(): Exception?

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

getResult

abstract fun getResult(): TResult!

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

abstract fun <X : Throwable?> getResult(exceptionType: Class<X!>): TResult!

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

abstract fun isCanceled(): Boolean

Returns true if the Task is canceled; false otherwise.

isComplete

abstract fun isComplete(): Boolean

Returns true if the Task is complete; false otherwise.

isSuccessful

abstract fun isSuccessful(): Boolean

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

onSuccessTask

fun <TContinuationResult> onSuccessTask(
    successContinuation: SuccessContinuation<TResult!, TContinuationResult!>
): Task<TContinuationResult!>

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

fun <TContinuationResult> onSuccessTask(
    executor: Executor,
    successContinuation: SuccessContinuation<TResult!, TContinuationResult!>
): Task<TContinuationResult!>

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: Executor

the executor to use to call the SuccessContinuation

See also
then