StorageTask

abstract class StorageTask<ResultT : StorageTask.ProvideError?> : ControllableTask

Known direct subclasses
FileDownloadTask

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

StreamDownloadTask

A task that downloads bytes of a GCS blob.

UploadTask

An controllable task that uploads and fires events for success, progress and failure.


A controllable Task that has a synchronized state machine.

Summary

Nested types

protected interface StorageTask.ProvideError

An object that returns an exception.

Base class for state.

Protected constructors

Public functions

StorageTask<ResultT!>

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

StorageTask<ResultT!>

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

StorageTask<ResultT!>

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

StorageTask<ResultT!>

Adds a listener that is called when the Task succeeds or fails.

StorageTask<ResultT!>
addOnCompleteListener(
    activity: Activity,
    listener: OnCompleteListener<ResultT!>
)

Adds a listener that is called when the Task succeeds or fails.

StorageTask<ResultT!>
addOnCompleteListener(
    executor: Executor,
    listener: OnCompleteListener<ResultT!>
)

Adds a listener that is called when the Task succeeds or fails.

StorageTask<ResultT!>

Adds a listener that is called if the Task fails.

StorageTask<ResultT!>

Adds a listener that is called if the Task fails.

StorageTask<ResultT!>

Adds a listener that is called if the Task fails.

StorageTask<ResultT!>

Adds a listener that is called when the Task becomes paused.

StorageTask<ResultT!>

Adds a listener that is called when the Task becomes paused.

StorageTask<ResultT!>

Adds a listener that is called when the Task becomes paused.

StorageTask<ResultT!>

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

StorageTask<ResultT!>
addOnProgressListener(
    activity: Activity,
    listener: OnProgressListener<Any!>
)

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

StorageTask<ResultT!>
addOnProgressListener(
    executor: Executor,
    listener: OnProgressListener<Any!>
)

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

StorageTask<ResultT!>

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

StorageTask<ResultT!>
addOnSuccessListener(
    activity: Activity,
    listener: OnSuccessListener<Any!>
)

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

StorageTask<ResultT!>
addOnSuccessListener(
    executor: Executor,
    listener: OnSuccessListener<Any!>
)

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

Boolean

Attempts to cancel the task.

Task<ContinuationResultT!>
<ContinuationResultT> continueWith(
    continuation: Continuation<ResultT!, ContinuationResultT!>
)

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

Task<ContinuationResultT!>
<ContinuationResultT> continueWith(
    executor: Executor,
    continuation: Continuation<ResultT!, ContinuationResultT!>
)

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

Task<ContinuationResultT!>
<ContinuationResultT> continueWithTask(
    continuation: Continuation<ResultT!, Task<ContinuationResultT!>!>
)

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

Task<ContinuationResultT!>
<ContinuationResultT> continueWithTask(
    executor: Executor,
    continuation: Continuation<ResultT!, Task<ContinuationResultT!>!>
)

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

Exception?

Returns the exception that caused the Task to fail.

ResultT

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

ResultT
<X : Throwable?> getResult(exceptionType: Class<X!>)

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

ResultT

Returns the current state of the task.

Boolean

Returns true if the task has been canceled.

Boolean

Returns true if the Task is complete; false otherwise.

Boolean

Returns true if the task is currently running.

Boolean

Returns true if the task has been paused.

Boolean

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

Task<ContinuationResultT!>
<ContinuationResultT> onSuccessTask(
    continuation: SuccessContinuation<ResultT!, ContinuationResultT!>
)

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<ContinuationResultT!>
<ContinuationResultT> onSuccessTask(
    executor: Executor,
    continuation: SuccessContinuation<ResultT!, ContinuationResultT!>
)

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

Boolean

Attempts to pause the task.

StorageTask<ResultT!>

Removes a listener.

StorageTask<ResultT!>

Removes a listener.

StorageTask<ResultT!>

Removes a listener.

StorageTask<ResultT!>

Removes a listener.

StorageTask<ResultT!>

Removes a listener.

StorageTask<ResultT!>

Removes a listener.

Boolean

Attempts to resume a paused task.

Protected properties

Any!

Extension properties

Flow<TaskState<T>>

Starts listening to this task's progress and emits its values via a Flow.

Flow<TaskState<T>>

This property is deprecated. Migrate to use the KTX API from the main module: https://firebase.google.com/docs/android/kotlin-migration.

Inherited functions

From com.google.android.gms.tasks.Task
abstract Boolean

Protected constructors

StorageTask

protected StorageTask()

Public functions

addOnCanceledListener

fun addOnCanceledListener(listener: OnCanceledListener): StorageTask<ResultT!>

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
StorageTask<ResultT!>

this Task

addOnCanceledListener

fun addOnCanceledListener(activity: Activity, listener: OnCanceledListener): StorageTask<ResultT!>

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
StorageTask<ResultT!>

this Task

addOnCanceledListener

fun addOnCanceledListener(executor: Executor, listener: OnCanceledListener): StorageTask<ResultT!>

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
StorageTask<ResultT!>

this Task

addOnCompleteListener

fun addOnCompleteListener(listener: OnCompleteListener<ResultT!>): StorageTask<ResultT!>

Adds a listener that is called when the Task succeeds or 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.

Returns
StorageTask<ResultT!>

this Task

addOnCompleteListener

fun addOnCompleteListener(
    activity: Activity,
    listener: OnCompleteListener<ResultT!>
): StorageTask<ResultT!>

Adds a listener that is called when the Task succeeds or 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
activity: Activity

When the supplied Activity stops, this listener will automatically be removed.

Returns
StorageTask<ResultT!>

this Task

addOnCompleteListener

fun addOnCompleteListener(
    executor: Executor,
    listener: OnCompleteListener<ResultT!>
): StorageTask<ResultT!>

Adds a listener that is called when the Task succeeds or 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
StorageTask<ResultT!>

this Task

addOnFailureListener

fun addOnFailureListener(listener: OnFailureListener): StorageTask<ResultT!>

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.

Returns
StorageTask<ResultT!>

this Task

addOnFailureListener

fun addOnFailureListener(activity: Activity, listener: OnFailureListener): StorageTask<ResultT!>

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
activity: Activity

When the supplied Activity stops, this listener will automatically be removed.

Returns
StorageTask<ResultT!>

this Task

addOnFailureListener

fun addOnFailureListener(executor: Executor, listener: OnFailureListener): StorageTask<ResultT!>

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
StorageTask<ResultT!>

this Task

addOnPausedListener

fun addOnPausedListener(listener: OnPausedListener<Any!>): StorageTask<ResultT!>

Adds a listener that is called when the Task becomes paused.

Returns
StorageTask<ResultT!>

this Task

addOnPausedListener

fun addOnPausedListener(activity: Activity, listener: OnPausedListener<Any!>): StorageTask<ResultT!>

Adds a listener that is called when the Task becomes paused.

Parameters
activity: Activity

When the supplied Activity stops, this listener will automatically be removed.

Returns
StorageTask<ResultT!>

this Task

addOnPausedListener

fun addOnPausedListener(executor: Executor, listener: OnPausedListener<Any!>): StorageTask<ResultT!>

Adds a listener that is called when the Task becomes paused.

Parameters
executor: Executor

the executor to use to call the listener

Returns
StorageTask<ResultT!>

this Task

addOnProgressListener

fun addOnProgressListener(listener: OnProgressListener<Any!>): StorageTask<ResultT!>

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

Returns
StorageTask<ResultT!>

this Task

addOnProgressListener

fun addOnProgressListener(
    activity: Activity,
    listener: OnProgressListener<Any!>
): StorageTask<ResultT!>

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

Parameters
activity: Activity

When the supplied Activity stops, this listener will automatically be removed.

Returns
StorageTask<ResultT!>

this Task

addOnProgressListener

fun addOnProgressListener(
    executor: Executor,
    listener: OnProgressListener<Any!>
): StorageTask<ResultT!>

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

Parameters
executor: Executor

the executor to use to call the listener

Returns
StorageTask<ResultT!>

this Task

addOnSuccessListener

fun addOnSuccessListener(listener: OnSuccessListener<Any!>): StorageTask<ResultT!>

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
StorageTask<ResultT!>

this Task

addOnSuccessListener

fun addOnSuccessListener(
    activity: Activity,
    listener: OnSuccessListener<Any!>
): StorageTask<ResultT!>

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
activity: Activity

When the supplied Activity stops, this listener will automatically be removed.

Returns
StorageTask<ResultT!>

this Task

addOnSuccessListener

fun addOnSuccessListener(
    executor: Executor,
    listener: OnSuccessListener<Any!>
): StorageTask<ResultT!>

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
StorageTask<ResultT!>

this Task

cancel

fun cancel(): Boolean

Attempts to cancel the task. A canceled task cannot be resumed later.

Returns
Boolean

true if this task is successfully being canceled.

continueWith

fun <ContinuationResultT> continueWith(
    continuation: Continuation<ResultT!, ContinuationResultT!>
): Task<ContinuationResultT!>

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.

See also
then

continueWith

fun <ContinuationResultT> continueWith(
    executor: Executor,
    continuation: Continuation<ResultT!, ContinuationResultT!>
): Task<ContinuationResultT!>

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

Parameters
executor: Executor

the executor to use to call the Continuation

See also
then

continueWithTask

fun <ContinuationResultT> continueWithTask(
    continuation: Continuation<ResultT!, Task<ContinuationResultT!>!>
): Task<ContinuationResultT!>

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.

See also
then

continueWithTask

fun <ContinuationResultT> continueWithTask(
    executor: Executor,
    continuation: Continuation<ResultT!, Task<ContinuationResultT!>!>
): Task<ContinuationResultT!>

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

Parameters
executor: Executor

the executor to use to call the Continuation

See also
then

getException

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

fun getResult(): ResultT

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

Throws
java.lang.IllegalStateException: java.lang.IllegalStateException

if the Task is not yet complete

com.google.android.gms.tasks.RuntimeExecutionException: com.google.android.gms.tasks.RuntimeExecutionException

if the Task failed with an exception

getResult

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

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

Throws
java.lang.IllegalStateException: java.lang.IllegalStateException

if the Task is not yet complete

X: X

if the Task failed with an exception of type X

com.google.android.gms.tasks.RuntimeExecutionException: com.google.android.gms.tasks.RuntimeExecutionException

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

getSnapshot

fun getSnapshot(): ResultT

Returns the current state of the task. This method will return state at any point of the tasks execution and may not be the final result.

isCanceled

fun isCanceled(): Boolean

Returns true if the task has been canceled.

isComplete

fun isComplete(): Boolean

Returns true if the Task is complete; false otherwise.

isInProgress

fun isInProgress(): Boolean

Returns true if the task is currently running.

isPaused

fun isPaused(): Boolean

Returns true if the task has been paused.

isSuccessful

fun isSuccessful(): Boolean

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

onSuccessTask

fun <ContinuationResultT> onSuccessTask(
    continuation: SuccessContinuation<ResultT!, ContinuationResultT!>
): Task<ContinuationResultT!>

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.

onSuccessTask

fun <ContinuationResultT> onSuccessTask(
    executor: Executor,
    continuation: SuccessContinuation<ResultT!, ContinuationResultT!>
): Task<ContinuationResultT!>

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

pause

fun pause(): Boolean

Attempts to pause the task. A paused task can later be resumed.

Returns
Boolean

true if this task is successfully being paused. Note that a task may not be immediately paused if it was executing another action and can still fail or complete.

removeOnCanceledListener

fun removeOnCanceledListener(listener: OnCanceledListener): StorageTask<ResultT!>

Removes a listener.

removeOnCompleteListener

fun removeOnCompleteListener(listener: OnCompleteListener<ResultT!>): StorageTask<ResultT!>

Removes a listener.

removeOnFailureListener

fun removeOnFailureListener(listener: OnFailureListener): StorageTask<ResultT!>

Removes a listener.

removeOnPausedListener

fun removeOnPausedListener(listener: OnPausedListener<Any!>): StorageTask<ResultT!>

Removes a listener.

removeOnProgressListener

fun removeOnProgressListener(listener: OnProgressListener<Any!>): StorageTask<ResultT!>

Removes a listener.

removeOnSuccessListener

fun removeOnSuccessListener(listener: OnSuccessListener<Any!>): StorageTask<ResultT!>

Removes a listener.

resume

fun resume(): Boolean

Attempts to resume a paused task.

Returns
Boolean

true if the task is successfully resumed. false if the task has an unrecoverable error or has entered another state that precludes resume.

Protected functions

onCanceled

protected fun onCanceled(): Unit

onFailure

protected fun onFailure(): Unit

onPaused

protected fun onPaused(): Unit

onProgress

protected fun onProgress(): Unit

onQueued

protected fun onQueued(): Unit

onSuccess

protected fun onSuccess(): Unit

Protected properties

syncObject

protected val syncObjectAny!

Extension properties

taskState

val StorageTask<T>.taskStateFlow<TaskState<T>>

Starts listening to this task's progress and emits its values via a Flow.

taskState

val StorageTask<T>.taskStateFlow<TaskState<T>>

Starts listening to this task's progress and emits its values via a Flow.

Deprecation Notice: The Kotlin extensions (KTX) APIs have been added to their respective main modules, and the Kotlin extension (KTX) APIs in com.google.firebase.firebase-storage-ktx are now deprecated. As early as April 2024, we'll no longer release KTX modules. For details, see the FAQ about this initiative.