目录

Task<TResult>

Interface Info

public interface Task<TResult>

Task API. Callback methods registered in this API will be called when task execution is complete.

Public Method Summary

Qualifier and Type

Method Name and Description

Task<TResult>

addOnCompleteListener(OnCompleteListener<TResult> onCompleteListener)

Adds one or more listeners that will be called in the main thread upon task completion. Multiple listeners added will be called in the order in which they were added.

Task<TResult>

addOnFailureListener(OnFailureListener onFailureListener)

Adds one or more listeners that will be called in the main thread upon task execution failure. Multiple listeners added will be called in the order in which they were added.

Task<TResult>

addOnSuccessListener(OnSuccessListener<TResult> onSuccessListener)

Adds one or more listeners that will be called in the main thread when a task is successfully executed. Multiple listeners added will be called in the order in which they were added.

Exception

getException()

Obtains the exception that causes the task execution failure.

TResult

getResult()

Obtains the execution result of a task if it is completed.

boolean

isCanceled()

Checks whether a task is canceled. The true value is returned if a task is canceled; false otherwise.

boolean

isComplete()

Checks whether a task is completed. The true value is returned if a task is completed; false otherwise.

boolean

isSuccessful()

Checks whether a task is executed successfully. The true value is returned if a task is executed successfully; false otherwise.

Public Methods

[h2]addOnCompleteListener

Method

public Task<TResult> addOnCompleteListener(OnCompleteListener<TResult> onCompleteListener)

Adds one or more listeners that will be called in the main thread upon task completion. Multiple listeners added will be called in the order in which they were added.

Parameters

Name

Description

onCompleteListener

Listener, which is called upon task completion.

Returns

Type

Description

Task<TResult>

Task execution result.

[h2]addOnFailureListener

Method

public Task<TResult> addOnFailureListener(OnFailureListener onFailureListener)

Adds one or more listeners that will be called in the main thread upon task execution failure. Multiple listeners added will be called in the order in which they were added.

Parameters

Name

Description

onFailureListener

Listener, which is called when a task failed to be executed.

Returns

Type

Description

Task<TResult>

Task execution result.

[h2]addOnSuccessListener

Method

public Task<TResult> addOnSuccessListener(OnSuccessListener<TResult> onSuccessListener)

Adds one or more listeners that will be called in the main thread upon task execution success. Multiple listeners added will be called in the order in which they were added.

Parameters

Name

Description

onSuccessListener

Listener, which is called when a task was executed successfully.

Returns

Type

Description

Task<TResult>

Task execution result.

[h2]getException

Method

public Exception getException()

Obtains the exception that causes the task execution failure.

Returns

Type

Description

Exception

Exception that causes the task execution failure.

[h2]getResult

Method

public TResult getResult()

Obtains the execution result of a task if it is completed.

Returns

Type

Description

TResult

Result of the task.

[h2]isCanceled

Method

public boolean isCanceled()

Checks whether a task is canceled. The true value is returned if a task is canceled; false otherwise.

Returns

Type

Description

boolean

true if the task is canceled; false otherwise.

[h2]isComplete

Method

public boolean isComplete()

Checks whether a task is completed. The true value is returned if a task is completed; false otherwise.

Returns

Type

Description

boolean

true if the task is completed; false otherwise.

[h2]isSuccessful

Method

public boolean isSuccessful()

Checks whether a task is executed successfully. The true value is returned if a task is executed successfully; false otherwise.

Returns

Type

Description

boolean

true if the task is executed successfully; false otherwise.