StorageTask
public abstract class StorageTask<ResultT extends StorageTask.ProvideError> extends ControllableTask
| java.lang.Object | ||||
| ↳ | 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. |
public class StorageTask.SnapshotBase implements StorageTask.ProvideErrorBase class for state. |
Protected fields |
|
|---|---|
final Object |
Protected constructors |
|---|
Public methods |
|
|---|---|
@NonNull StorageTask<ResultT> |
addOnCanceledListener(@NonNull OnCanceledListener listener)Adds a listener that is called if the Task is canceled. |
@NonNull StorageTask<ResultT> |
addOnCanceledListener(Adds an Activity-scoped listener that is called if the Task is canceled. |
@NonNull StorageTask<ResultT> |
addOnCanceledListener(Adds a listener that is called if the Task is canceled. |
@NonNull StorageTask<ResultT> |
addOnCompleteListener(@NonNull OnCompleteListener<ResultT> listener)Adds a listener that is called when the Task succeeds or fails. |
@NonNull StorageTask<ResultT> |
addOnCompleteListener(Adds a listener that is called when the Task succeeds or fails. |
@NonNull StorageTask<ResultT> |
addOnCompleteListener(Adds a listener that is called when the Task succeeds or fails. |
@NonNull StorageTask<ResultT> |
addOnFailureListener(@NonNull OnFailureListener listener)Adds a listener that is called if the Task fails. |
@NonNull StorageTask<ResultT> |
addOnFailureListener(Adds a listener that is called if the Task fails. |
@NonNull StorageTask<ResultT> |
addOnFailureListener(Adds a listener that is called if the Task fails. |
@NonNull StorageTask<ResultT> |
addOnPausedListener(@NonNull OnPausedListener<Object> listener)Adds a listener that is called when the Task becomes paused. |
@NonNull StorageTask<ResultT> |
addOnPausedListener(Adds a listener that is called when the Task becomes paused. |
@NonNull StorageTask<ResultT> |
addOnPausedListener(Adds a listener that is called when the Task becomes paused. |
@NonNull StorageTask<ResultT> |
addOnProgressListener(@NonNull OnProgressListener<Object> listener)Adds a listener that is called periodically while the ControllableTask executes. |
@NonNull StorageTask<ResultT> |
addOnProgressListener(Adds a listener that is called periodically while the ControllableTask executes. |
@NonNull StorageTask<ResultT> |
addOnProgressListener(Adds a listener that is called periodically while the ControllableTask executes. |
@NonNull StorageTask<ResultT> |
addOnSuccessListener(@NonNull OnSuccessListener<Object> listener)Adds a listener that is called if the Task completes successfully. |
@NonNull StorageTask<ResultT> |
addOnSuccessListener(Adds a listener that is called if the Task completes successfully. |
@NonNull StorageTask<ResultT> |
addOnSuccessListener(Adds a listener that is called if the Task completes successfully. |
boolean |
cancel()Attempts to cancel the task. |
@NonNull Task<ContinuationResultT> |
<ContinuationResultT> continueWith(Returns a new Task that will be completed with the result of applying the specified Continuation to this Task. |
@NonNull Task<ContinuationResultT> |
<ContinuationResultT> continueWith(Returns a new Task that will be completed with the result of applying the specified Continuation to this Task. |
@NonNull Task<ContinuationResultT> |
<ContinuationResultT> continueWithTask(Returns a new Task that will be completed with the result of applying the specified Continuation to this Task. |
@NonNull Task<ContinuationResultT> |
<ContinuationResultT> continueWithTask(Returns a new Task that will be completed with the result of applying the specified Continuation to this Task. |
@Nullable Exception |
Returns the exception that caused the Task to fail. |
@NonNull ResultT |
Gets the result of the Task, if it has already completed. |
@NonNull ResultT |
Gets the result of the Task, if it has already completed. |
@NonNull ResultT |
Returns the current state of the task. |
boolean |
Returns |
boolean |
Returns |
boolean |
Returns |
boolean |
isPaused()Returns |
boolean |
Returns |
@NonNull 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. |
@NonNull 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. |
@NonNull StorageTask<ResultT> |
removeOnCanceledListener(@NonNull OnCanceledListener listener)Removes a listener. |
@NonNull StorageTask<ResultT> |
removeOnCompleteListener(@NonNull OnCompleteListener<ResultT> listener)Removes a listener. |
@NonNull StorageTask<ResultT> |
removeOnFailureListener(@NonNull OnFailureListener listener)Removes a listener. |
@NonNull StorageTask<ResultT> |
removeOnPausedListener(@NonNull OnPausedListener<Object> listener)Removes a listener. |
@NonNull StorageTask<ResultT> |
removeOnProgressListener(@NonNull OnProgressListener<Object> listener)Removes a listener. |
@NonNull StorageTask<ResultT> |
removeOnSuccessListener(@NonNull OnSuccessListener<Object> listener)Removes a listener. |
boolean |
resume()Attempts to resume a paused task. |
Extension functions |
|
|---|---|
final @NonNull Flow<@NonNull TaskState<@NonNull T>> |
StorageKt.getTaskState(@NonNull StorageTask<@NonNull T> receiver) |
Inherited methods |
||
|---|---|---|
|
Protected fields
Protected constructors
Public methods
addOnCanceledListener
public @NonNull StorageTask<ResultT> 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.
| Returns | |
|---|---|
@NonNull StorageTask<ResultT> |
this Task |
addOnCanceledListener
public @NonNull StorageTask<ResultT> 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.
| Returns | |
|---|---|
@NonNull StorageTask<ResultT> |
this Task |
addOnCanceledListener
public @NonNull StorageTask<ResultT> addOnCanceledListener(
@NonNull Executor executor,
@NonNull OnCanceledListener listener
)
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.
| Returns | |
|---|---|
@NonNull StorageTask<ResultT> |
this Task |
addOnCompleteListener
public @NonNull StorageTask<ResultT> addOnCompleteListener(@NonNull OnCompleteListener<ResultT> listener)
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 | |
|---|---|
@NonNull StorageTask<ResultT> |
this Task |
addOnCompleteListener
public @NonNull StorageTask<ResultT> addOnCompleteListener(
@NonNull Activity activity,
@NonNull OnCompleteListener<ResultT> listener
)
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 | |
|---|---|
@NonNull Activity activity |
When the supplied |
| Returns | |
|---|---|
@NonNull StorageTask<ResultT> |
this Task |
addOnCompleteListener
public @NonNull StorageTask<ResultT> addOnCompleteListener(
@NonNull Executor executor,
@NonNull OnCompleteListener<ResultT> listener
)
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.
| Returns | |
|---|---|
@NonNull StorageTask<ResultT> |
this Task |
addOnFailureListener
public @NonNull StorageTask<ResultT> 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.
| Returns | |
|---|---|
@NonNull StorageTask<ResultT> |
this Task |
addOnFailureListener
public @NonNull StorageTask<ResultT> addOnFailureListener(
@NonNull Activity activity,
@NonNull OnFailureListener listener
)
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 | |
|---|---|
@NonNull Activity activity |
When the supplied |
| Returns | |
|---|---|
@NonNull StorageTask<ResultT> |
this Task |
addOnFailureListener
public @NonNull StorageTask<ResultT> addOnFailureListener(
@NonNull Executor executor,
@NonNull OnFailureListener listener
)
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.
| Returns | |
|---|---|
@NonNull StorageTask<ResultT> |
this Task |
addOnPausedListener
public @NonNull StorageTask<ResultT> addOnPausedListener(@NonNull OnPausedListener<Object> listener)
Adds a listener that is called when the Task becomes paused.
| Returns | |
|---|---|
@NonNull StorageTask<ResultT> |
this Task |
addOnPausedListener
public @NonNull StorageTask<ResultT> addOnPausedListener(
@NonNull Activity activity,
@NonNull OnPausedListener<Object> listener
)
Adds a listener that is called when the Task becomes paused.
| Parameters | |
|---|---|
@NonNull Activity activity |
When the supplied |
| Returns | |
|---|---|
@NonNull StorageTask<ResultT> |
this Task |
addOnPausedListener
public @NonNull StorageTask<ResultT> addOnPausedListener(
@NonNull Executor executor,
@NonNull OnPausedListener<Object> listener
)
Adds a listener that is called when the Task becomes paused.
| Returns | |
|---|---|
@NonNull StorageTask<ResultT> |
this Task |
addOnProgressListener
public @NonNull StorageTask<ResultT> addOnProgressListener(@NonNull OnProgressListener<Object> listener)
Adds a listener that is called periodically while the ControllableTask executes.
| Returns | |
|---|---|
@NonNull StorageTask<ResultT> |
this Task |
addOnProgressListener
public @NonNull StorageTask<ResultT> addOnProgressListener(
@NonNull Activity activity,
@NonNull OnProgressListener<Object> listener
)
Adds a listener that is called periodically while the ControllableTask executes.
| Parameters | |
|---|---|
@NonNull Activity activity |
When the supplied |
| Returns | |
|---|---|
@NonNull StorageTask<ResultT> |
this Task |
addOnProgressListener
public @NonNull StorageTask<ResultT> addOnProgressListener(
@NonNull Executor executor,
@NonNull OnProgressListener<Object> listener
)
Adds a listener that is called periodically while the ControllableTask executes.
| Returns | |
|---|---|
@NonNull StorageTask<ResultT> |
this Task |
addOnSuccessListener
public @NonNull StorageTask<ResultT> 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.
| Returns | |
|---|---|
@NonNull StorageTask<ResultT> |
this Task |
addOnSuccessListener
public @NonNull StorageTask<ResultT> addOnSuccessListener(
@NonNull Activity activity,
@NonNull OnSuccessListener<Object> listener
)
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 | |
|---|---|
@NonNull Activity activity |
When the supplied |
| Returns | |
|---|---|
@NonNull StorageTask<ResultT> |
this Task |
addOnSuccessListener
public @NonNull StorageTask<ResultT> addOnSuccessListener(
@NonNull Executor executor,
@NonNull OnSuccessListener<Object> listener
)
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.
| Returns | |
|---|---|
@NonNull StorageTask<ResultT> |
this Task |
cancel
public boolean cancel()
Attempts to cancel the task. A canceled task cannot be resumed later.
| Returns | |
|---|---|
boolean |
|
continueWith
public @NonNull Task<ContinuationResultT> <ContinuationResultT> continueWith(
@NonNull Continuation<ResultT, ContinuationResultT> 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.
| See also | |
|---|---|
then |
continueWith
public @NonNull Task<ContinuationResultT> <ContinuationResultT> continueWith(
@NonNull Executor executor,
@NonNull Continuation<ResultT, ContinuationResultT> continuation
)
Returns a new Task that will be completed with the result of applying the specified Continuation to this Task.
| See also | |
|---|---|
then |
continueWithTask
public @NonNull Task<ContinuationResultT> <ContinuationResultT> continueWithTask(
@NonNull Continuation<ResultT, Task<ContinuationResultT>> 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.
| See also | |
|---|---|
then |
continueWithTask
public @NonNull Task<ContinuationResultT> <ContinuationResultT> continueWithTask(
@NonNull Executor executor,
@NonNull Continuation<ResultT, Task<ContinuationResultT>> continuation
)
Returns a new Task that will be completed with the result of applying the specified Continuation to this Task.
| See also | |
|---|---|
then |
getException
public @Nullable Exception getException()
Returns the exception that caused the Task to fail. Returns null if the Task is not yet complete, or completed successfully.
getResult
public @NonNull ResultT getResult()
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
public @NonNull ResultT <X extends Throwable> getResult(@NonNull Class<X> exceptionType)
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
public @NonNull ResultT getSnapshot()
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
public boolean isSuccessful()
Returns true if the Task has completed successfully; false otherwise.
onSuccessTask
public @NonNull Task<ContinuationResultT> <ContinuationResultT> onSuccessTask(
@NonNull SuccessContinuation<ResultT, ContinuationResultT> continuation
)
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
public @NonNull Task<ContinuationResultT> <ContinuationResultT> onSuccessTask(
@NonNull Executor executor,
@NonNull SuccessContinuation<ResultT, ContinuationResultT> continuation
)
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.
| See also | |
|---|---|
SuccessContinuation |
pause
public boolean pause()
Attempts to pause the task. A paused task can later be resumed.
| Returns | |
|---|---|
boolean |
|
removeOnCanceledListener
public @NonNull StorageTask<ResultT> removeOnCanceledListener(@NonNull OnCanceledListener listener)
Removes a listener.
removeOnCompleteListener
public @NonNull StorageTask<ResultT> removeOnCompleteListener(@NonNull OnCompleteListener<ResultT> listener)
Removes a listener.
removeOnFailureListener
public @NonNull StorageTask<ResultT> removeOnFailureListener(@NonNull OnFailureListener listener)
Removes a listener.
removeOnPausedListener
public @NonNull StorageTask<ResultT> removeOnPausedListener(@NonNull OnPausedListener<Object> listener)
Removes a listener.
removeOnProgressListener
public @NonNull StorageTask<ResultT> removeOnProgressListener(@NonNull OnProgressListener<Object> listener)
Removes a listener.
removeOnSuccessListener
public @NonNull StorageTask<ResultT> removeOnSuccessListener(@NonNull OnSuccessListener<Object> listener)
Removes a listener.
resume
public boolean resume()
Attempts to resume a paused task.
| Returns | |
|---|---|
boolean |
|
Protected methods
Extension functions
StorageKt.getTaskState
public final @NonNull Flow<@NonNull TaskState<@NonNull T>> StorageKt.getTaskState(@NonNull StorageTask<@NonNull T> receiver)