CancellableTask

public abstract classCancellableTask<StateT> extendsTask

Known direct subclasses
ControllableTask

Represents an asynchronous operation that can be paused, resumed and canceled.

Known indirect subclasses
FileDownloadTask

A task that downloads bytes of a GCS blob to a specified File.

StorageTask

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.


Represents an asynchronous operation that can be canceled.

Parameters
<StateT>

the type of state this operation returns in events.

Summary

Public constructors

Public methods

abstract @NonNullCancellableTask<StateT>

Adds a listener that is called periodically while the ControllableTask executes.

abstract @NonNullCancellableTask<StateT>

Adds a listener that is called periodically while the ControllableTask executes.

abstract @NonNullCancellableTask<StateT>

Adds a listener that is called periodically while the ControllableTask executes.

abstract boolean

Attempts to cancel the task.

abstract boolean
abstract boolean

Inherited methods

Fromcom.google.android.gms.tasks.Task
Task<TResult>
Task<TResult>
abstractTask<TResult>
abstractTask<TResult>
Task<TContinuationResult>
<TContinuationResult>continueWith(
    Continuation<TResult, TContinuationResult> p
)
Task<TContinuationResult>
<TContinuationResult>continueWithTask(
    Continuation<TResult, Task<TContinuationResult>> p
)
abstractException
abstract TResult
abstract boolean
abstract boolean
Task<TContinuationResult>
<TContinuationResult>onSuccessTask(
    SuccessContinuation<TResult, TContinuationResult> p
)

Public constructors

CancellableTask

public CancellableTask()

Public methods

addOnProgressListener

public abstract @NonNullCancellableTask<StateT> addOnProgressListener(@NonNullOnProgressListener<Object> listener)

Adds a listener that is called periodically while the ControllableTask executes.

Returns
@NonNullCancellableTask<StateT>

this Task

addOnProgressListener

public abstract @NonNullCancellableTask<StateT> addOnProgressListener(
    @NonNullActivity activity,
    @NonNullOnProgressListener<Object> listener
)

Adds a listener that is called periodically while the ControllableTask executes.

Parameters
@NonNullActivity activity

When the suppliedActivity stops, this listener will automatically be removed.

Returns
@NonNullCancellableTask<StateT>

this Task

addOnProgressListener

public abstract @NonNullCancellableTask<StateT> addOnProgressListener(
    @NonNullExecutor executor,
    @NonNullOnProgressListener<Object> listener
)

Adds a listener that is called periodically while the ControllableTask executes.

Parameters
@NonNullExecutor executor

the executor to use to call the listener

Returns
@NonNullCancellableTask<StateT>

this Task

cancel

public abstract boolean cancel()

Attempts to cancel the task. A canceled task cannot be resumed later. A canceled task calls back on listeners subscribed toaddOnFailureListener with an exception that indicates the task was canceled.

Returns
boolean

true if this task was successfully canceled or is in the process of being canceled. Returns false if the task is already completed or in a state that cannot be canceled.

isCanceled

public abstract boolean isCanceled()
Returns
boolean

true if the task has been canceled.

isInProgress

public abstract boolean isInProgress()
Returns
boolean

true if the task is currently running.

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

Last updated 2025-07-21 UTC.