A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developers.google.com/android/reference/com/google/android/gms/tasks/Task below:

Task | Google Play services

Skip to main content

Stay organized with collections Save and categorize content based on your preferences.

public abstract class Task<TResult>

Represents an asynchronous operation.

Parameters <TResult>

the type of the result of the operation

Summary Public constructors Task() Public methods @NonNull Task<TResult> @CanIgnoreReturnValue
addOnCanceledListener(@NonNull OnCanceledListener listener)

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

@NonNull Task<TResult> @CanIgnoreReturnValue
addOnCanceledListener(
    @NonNull Activity activity,
    @NonNull OnCanceledListener listener
)

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

@NonNull Task<TResult> @CanIgnoreReturnValue
addOnCanceledListener(
    @NonNull Executor executor,
    @NonNull OnCanceledListener listener
)

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

@NonNull Task<TResult> @CanIgnoreReturnValue
addOnCompleteListener(@NonNull OnCompleteListener<TResult> listener)

Adds a listener that is called when the Task completes.

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

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

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

Adds a listener that is called when the Task completes.

abstract @NonNull Task<TResult> @CanIgnoreReturnValue
addOnFailureListener(@NonNull OnFailureListener listener)

Adds a listener that is called if the Task fails.

abstract @NonNull Task<TResult> @CanIgnoreReturnValue
addOnFailureListener(
    @NonNull Activity activity,
    @NonNull OnFailureListener listener
)

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

abstract @NonNull Task<TResult> @CanIgnoreReturnValue
addOnFailureListener(
    @NonNull Executor executor,
    @NonNull OnFailureListener listener
)

Adds a listener that is called if the Task fails.

abstract @NonNull Task<TResult> @CanIgnoreReturnValue
addOnSuccessListener(@NonNull OnSuccessListener<Object> listener)

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

abstract @NonNull Task<TResult> @CanIgnoreReturnValue
addOnSuccessListener(
    @NonNull Activity activity,
    @NonNull OnSuccessListener<Object> listener
)

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

abstract @NonNull Task<TResult> @CanIgnoreReturnValue
addOnSuccessListener(
    @NonNull Executor executor,
    @NonNull OnSuccessListener<Object> listener
)

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

@NonNull Task<TContinuationResult> <TContinuationResult> continueWith(
    @NonNull Continuation<TResult, TContinuationResult> continuation
)

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

@NonNull Task<TContinuationResult> <TContinuationResult> continueWith(
    @NonNull Executor executor,
    @NonNull Continuation<TResult, TContinuationResult> continuation
)

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

@NonNull Task<TContinuationResult> <TContinuationResult> continueWithTask(
    @NonNull Continuation<TResult, Task<TContinuationResult>> continuation
)

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

@NonNull Task<TContinuationResult> <TContinuationResult> continueWithTask(
    @NonNull Executor executor,
    @NonNull 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 @Nullable 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 TResult <X extends Throwable> getResult(@NonNull Class<X> exceptionType)

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

abstract boolean isCanceled()

Returns true if the Task is canceled; false otherwise.

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.

@NonNull Task<TContinuationResult> <TContinuationResult> onSuccessTask(
    @NonNull SuccessContinuation<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.

@NonNull Task<TContinuationResult> <TContinuationResult> onSuccessTask(
    @NonNull Executor executor,
    @NonNull SuccessContinuation<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 methods
@CanIgnoreReturnValue
public @NonNull Task<TResult> addOnCanceledListener(@NonNull 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.

@CanIgnoreReturnValue
public @NonNull Task<TResult> addOnCanceledListener(
    @NonNull Activity activity,
    @NonNull 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.

@CanIgnoreReturnValue
public @NonNull Task<TResult> addOnCompleteListener(@NonNull 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. 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.

@CanIgnoreReturnValue
public @NonNull Task<TResult> addOnCompleteListener(
    @NonNull Activity activity,
    @NonNull 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. 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.

@CanIgnoreReturnValue
public @NonNull Task<TResult> addOnCompleteListener(
    @NonNull Executor executor,
    @NonNull 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. 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 @NonNull Executor executor

the executor to use to call the listener

@CanIgnoreReturnValue
public abstract @NonNull Task<TResult> addOnFailureListener(@NonNull 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.

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

@CanIgnoreReturnValue
public abstract @NonNull Task<TResult> addOnFailureListener(
    @NonNull Activity activity,
    @NonNull 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.

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.

@CanIgnoreReturnValue
public abstract @NonNull Task<TResult> addOnSuccessListener(@NonNull OnSuccessListener<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.

@CanIgnoreReturnValue
public abstract @NonNull Task<TResult> addOnSuccessListener(
    @NonNull Activity activity,
    @NonNull OnSuccessListener<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 during onStop.

public @NonNull Task<TContinuationResult> <TContinuationResult> continueWith(
    @NonNull 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.

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

public @NonNull Task<TContinuationResult> <TContinuationResult> continueWith(
    @NonNull Executor executor,
    @NonNull Continuation<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 @NonNull Executor executor

the executor to use to call the Continuation

public @NonNull Task<TContinuationResult> <TContinuationResult> continueWithTask(
    @NonNull 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.

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

public @NonNull Task<TContinuationResult> <TContinuationResult> continueWithTask(
    @NonNull Executor executor,
    @NonNull Continuation<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 @NonNull Executor executor

the executor to use to call the Continuation

public abstract @Nullable 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.

public abstract boolean isCanceled()

Returns true if the Task is canceled; false otherwise.

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.

public @NonNull Task<TContinuationResult> <TContinuationResult> onSuccessTask(
    @NonNull SuccessContinuation<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.

public @NonNull Task<TContinuationResult> <TContinuationResult> onSuccessTask(
    @NonNull Executor executor,
    @NonNull SuccessContinuation<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 @NonNull Executor executor

the executor to use to call the SuccessContinuation

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-03-17 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-03-17 UTC."],[[["`Task` represents asynchronous operations in Android, returning a result of type `\u003cTResult\u003e`."],["Provides methods like `getResult()`, `onSuccessTask()`, and `addOnCompleteListener()` to manage results, chain operations, and attach listeners."],["`continueWith()` and `continueWithTask()` allow creating new tasks that execute after the current one completes, useful for sequential operations."],["Includes functionalities for checking task status, such as `isComplete()`, `isSuccessful()`, and `isCanceled()`."],["Listeners like `addOnSuccessListener()` and `addOnFailureListener()` can be attached to respond to task outcomes and are typically executed on the main thread."]]],["The `Task` class represents an asynchronous operation, allowing listeners to be added for cancellation, completion, failure, and success events. Tasks can be chained using `continueWith` or `onSuccessTask`, with optional executor specification to set the thread. Result access is provided via `getResult`, `getException`, and state checks like `isCanceled`, `isComplete`, and `isSuccessful`. Listeners are notified immediately if the task has already completed, or upon event occurrence and can also be activity-scoped.\n"]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4