StorageTask
abstract class StorageTask<ResultT : StorageTask.ProvideError?> : ControllableTask
| kotlin.Any | ||||
| ↳ | com.google.android.gms.tasks.Task | |||
| ↳ | com.google.firebase.storage.CancellableTask | |||
| ↳ | com.google.firebase.storage.ControllableTask | |||
| ↳ | com.google.firebase.storage.StorageTask |
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.ProvideErrorAn object that returns an exception. |
|
Base class for state. |
Protected constructors |
|---|
Public functions |
|
|---|---|
StorageTask<ResultT!> |
addOnCanceledListener(listener: OnCanceledListener)Adds a listener that is called if the Task is canceled. |
StorageTask<ResultT!> |
addOnCanceledListener(activity: Activity, listener: OnCanceledListener)Adds an Activity-scoped listener that is called if the Task is canceled. |
StorageTask<ResultT!> |
addOnCanceledListener(executor: Executor, listener: OnCanceledListener)Adds a listener that is called if the Task is canceled. |
StorageTask<ResultT!> |
addOnCompleteListener(listener: OnCompleteListener<ResultT!>)Adds a listener that is called when the Task succeeds or fails. |
StorageTask<ResultT!> |
addOnCompleteListener(Adds a listener that is called when the Task succeeds or fails. |
StorageTask<ResultT!> |
addOnCompleteListener(Adds a listener that is called when the Task succeeds or fails. |
StorageTask<ResultT!> |
addOnFailureListener(listener: OnFailureListener)Adds a listener that is called if the Task fails. |
StorageTask<ResultT!> |
addOnFailureListener(activity: Activity, listener: OnFailureListener)Adds a listener that is called if the Task fails. |
StorageTask<ResultT!> |
addOnFailureListener(executor: Executor, listener: OnFailureListener)Adds a listener that is called if the Task fails. |
StorageTask<ResultT!> |
addOnPausedListener(listener: OnPausedListener<Any!>)Adds a listener that is called when the Task becomes paused. |
StorageTask<ResultT!> |
addOnPausedListener(activity: Activity, listener: OnPausedListener<Any!>)Adds a listener that is called when the Task becomes paused. |
StorageTask<ResultT!> |
addOnPausedListener(executor: Executor, listener: OnPausedListener<Any!>)Adds a listener that is called when the Task becomes paused. |
StorageTask<ResultT!> |
addOnProgressListener(listener: OnProgressListener<Any!>)Adds a listener that is called periodically while the ControllableTask executes. |
StorageTask<ResultT!> |
addOnProgressListener(Adds a listener that is called periodically while the ControllableTask executes. |
StorageTask<ResultT!> |
addOnProgressListener(Adds a listener that is called periodically while the ControllableTask executes. |
StorageTask<ResultT!> |
addOnSuccessListener(listener: OnSuccessListener<Any!>)Adds a listener that is called if the Task completes successfully. |
StorageTask<ResultT!> |
addOnSuccessListener(Adds a listener that is called if the Task completes successfully. |
StorageTask<ResultT!> |
addOnSuccessListener(Adds a listener that is called if the Task completes successfully. |
Boolean |
cancel()Attempts to cancel the task. |
Task<ContinuationResultT!> |
<ContinuationResultT> continueWith(Returns a new Task that will be completed with the result of applying the specified Continuation to this Task. |
Task<ContinuationResultT!> |
<ContinuationResultT> continueWith(Returns a new Task that will be completed with the result of applying the specified Continuation to this Task. |
Task<ContinuationResultT!> |
<ContinuationResultT> continueWithTask(Returns a new Task that will be completed with the result of applying the specified Continuation to this Task. |
Task<ContinuationResultT!> |
<ContinuationResultT> continueWithTask(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 |
Gets the result of the Task, if it has already completed. |
ResultT |
Returns the current state of the task. |
Boolean |
Returns |
Boolean |
Returns |
Boolean |
Returns |
Boolean |
isPaused()Returns |
Boolean |
Returns |
Task<ContinuationResultT!> |
<ContinuationResultT> onSuccessTask(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(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 |
pause()Attempts to pause the task. |
StorageTask<ResultT!> |
removeOnCanceledListener(listener: OnCanceledListener)Removes a listener. |
StorageTask<ResultT!> |
removeOnCompleteListener(listener: OnCompleteListener<ResultT!>)Removes a listener. |
StorageTask<ResultT!> |
removeOnFailureListener(listener: OnFailureListener)Removes a listener. |
StorageTask<ResultT!> |
removeOnPausedListener(listener: OnPausedListener<Any!>)Removes a listener. |
StorageTask<ResultT!> |
removeOnProgressListener(listener: OnProgressListener<Any!>)Removes a listener. |
StorageTask<ResultT!> |
removeOnSuccessListener(listener: OnSuccessListener<Any!>)Removes a listener. |
Boolean |
resume()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 |
Inherited functions |
||
|---|---|---|
|
Protected constructors
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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
|
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.
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.
| See also | |
|---|---|
SuccessContinuation |
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 |
| See also | |
|---|---|
SuccessContinuation |
pause
fun pause(): Boolean
Attempts to pause the task. A paused task can later be resumed.
| Returns | |
|---|---|
Boolean |
|
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.
Protected functions
Protected properties
Extension properties
taskState
val StorageTask<T>.taskState: Flow<TaskState<T>>
Starts listening to this task's progress and emits its values via a Flow.
-
When the returned flow starts being collected, it attaches the following listeners:
OnProgressListener,OnPausedListener,OnCompleteListener. -
When the flow completes the listeners will be removed.