Android SDK Version


public final class Task<TResult extends Object>
Represents the result of an asynchronous operation.
Nested Class Summary
Modifier and TypeClassDescription
public interfaceTask.UnobservedExceptionHandler
Interface for handlers invoked when a failed Task is about to be finalized, but the exception has not been consumed.
The handler will execute in the GC thread, so if the handler needs to do anything time consuming or complex it is a good idea to fire off a Task to handle the exception.
public final classTask.TaskCompletionSource
public classTask.Companion
Field Summary
Modifier and TypeFieldDescription
private final BooleanisCompleted
private final BooleanisCancelled
private final BooleanisFaulted
private final TResultresult
private final Exceptionerror
Method Summary
Modifier and TypeMethodDescription
final BooleangetIsCompleted()
final BooleangetIsCancelled()
final BooleangetIsFaulted()
final TResultgetResult()
final ExceptiongetError()
final UnitwaitForCompletion() Blocks until the task is complete.
final BooleanwaitForCompletion(Long duration, TimeUnit timeUnit) Blocks until the task is complete or times out.
final <TOut extends Any> Task<TOut>cast() Makes a fluent cast of a Task's result possible, avoiding an extra continuation just to cast the type of the result.
final Task<Void>makeVoid() Turns a Task<T> into a Task<Void>, dropping any result.
final Task<Void>continueWhile(Callable<Boolean> predicate, Continuation<Void, Task<Void>> continuation) Continues a task with the equivalent of a Task-based while loop, where the body of the loop is a task continuation.
final Task<Void>continueWhile(Callable<Boolean> predicate, Continuation<Void, Task<Void>> continuation, CancellationToken ct) Continues a task with the equivalent of a Task-based while loop, where the body of the loop is a task continuation.
final Task<Void>continueWhile(Callable<Boolean> predicate, Continuation<Void, Task<Void>> continuation, Executor executor, CancellationToken ct) Continues a task with the equivalent of a Task-based while loop, where the body of the loop is a task continuation.
final <TContinuationResult extends Any> Task<TContinuationResult>continueWith(Continuation<TResult, TContinuationResult> continuation, Executor executor) Adds a continuation that will be scheduled using the executor, returning a new task that completes after the continuation has finished running.
final <TContinuationResult extends Any> Task<TContinuationResult>continueWith(Continuation<TResult, TContinuationResult> continuation, Executor executor, CancellationToken ct) Adds a continuation that will be scheduled using the executor, returning a new task that completes after the continuation has finished running.
final <TContinuationResult extends Any> Task<TContinuationResult>continueWith(Continuation<TResult, TContinuationResult> continuation) Adds a synchronous continuation to this task, returning a new task that completes after the continuation has finished running.
final <TContinuationResult extends Any> Task<TContinuationResult>continueWith(Continuation<TResult, TContinuationResult> continuation, CancellationToken ct) Adds a synchronous continuation to this task, returning a new task that completes after the continuation has finished running.
final <TContinuationResult extends Any> Task<TContinuationResult>continueWithTask(Continuation<TResult, Task<TContinuationResult>> continuation, Executor executor) Adds an Task-based continuation to this task that will be scheduled using the executor, returning a new task that completes after the task returned by the continuation has completed.
final <TContinuationResult extends Any> Task<TContinuationResult>continueWithTask(Continuation<TResult, Task<TContinuationResult>> continuation, Executor executor, CancellationToken ct) Adds an Task-based continuation to this task that will be scheduled using the executor, returning a new task that completes after the task returned by the continuation has completed.
final <TContinuationResult extends Any> Task<TContinuationResult>continueWithTask(Continuation<TResult, Task<TContinuationResult>> continuation) Adds an asynchronous continuation to this task, returning a new task that completes after the task returned by the continuation has completed.
final <TContinuationResult extends Any> Task<TContinuationResult>continueWithTask(Continuation<TResult, Task<TContinuationResult>> continuation, CancellationToken ct) Adds an asynchronous continuation to this task, returning a new task that completes after the task returned by the continuation has completed.
final <TContinuationResult extends Any> Task<TContinuationResult>onSuccess(Continuation<TResult, TContinuationResult> continuation, Executor executor) Runs a continuation when a task completes successfully, forwarding along Exception or cancellation.
final <TContinuationResult extends Any> Task<TContinuationResult>onSuccess(Continuation<TResult, TContinuationResult> continuation, Executor executor, CancellationToken ct) Runs a continuation when a task completes successfully, forwarding along Exception or cancellation.
final <TContinuationResult extends Any> Task<TContinuationResult>onSuccess(Continuation<TResult, TContinuationResult> continuation) Runs a continuation when a task completes successfully, forwarding along Exceptions or cancellation.
final <TContinuationResult extends Any> Task<TContinuationResult>onSuccess(Continuation<TResult, TContinuationResult> continuation, CancellationToken ct) Runs a continuation when a task completes successfully, forwarding along Exceptions or cancellation.
final <TContinuationResult extends Any> Task<TContinuationResult>onSuccessTask(Continuation<TResult, Task<TContinuationResult>> continuation, Executor executor) Runs a continuation when a task completes successfully, forwarding along Exceptions or cancellation.
final <TContinuationResult extends Any> Task<TContinuationResult>onSuccessTask(Continuation<TResult, Task<TContinuationResult>> continuation, Executor executor, CancellationToken ct) Runs a continuation when a task completes successfully, forwarding along Exceptions or cancellation.
final <TContinuationResult extends Any> Task<TContinuationResult>onSuccessTask(Continuation<TResult, Task<TContinuationResult>> continuation) Runs a continuation when a task completes successfully, forwarding along [ ]s or cancellation.
final <TContinuationResult extends Any> Task<TContinuationResult>onSuccessTask(Continuation<TResult, Task<TContinuationResult>> continuation, CancellationToken ct) Runs a continuation when a task completes successfully, forwarding along [ ]s or cancellation.
final BooleantrySetCancelled() Sets the cancelled flag on the Task if the Task hasn't already been completed.
final BooleantrySetResult(TResult result) Sets the result on the Task if the Task hasn't already been completed.
final BooleantrySetError(Exception error) Sets the error on the Task if the Task hasn't already been completed.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Method Detail

getIsCompleted

 final BooleangetIsCompleted()

getIsCancelled

 final BooleangetIsCancelled()

getIsFaulted

 final BooleangetIsFaulted()

getResult

 final TResultgetResult()

getError

 final ExceptiongetError()

waitForCompletion

 final UnitwaitForCompletion()
Blocks until the task is complete.

waitForCompletion

 final BooleanwaitForCompletion(Long duration, TimeUnit timeUnit)
Blocks until the task is complete or times out.

cast

 final <TOut extends Any> Task<TOut> cast()
Makes a fluent cast of a Task's result possible, avoiding an extra continuation just to cast the type of the result.

makeVoid

 final Task<Void> makeVoid()
Turns a Task<T> into a Task<Void>, dropping any result. </Void></T>

continueWhile

 final Task<Void> continueWhile(Callable<Boolean> predicate, Continuation<Void, Task<Void>> continuation)
Continues a task with the equivalent of a Task-based while loop, where the body of the loop is a task continuation.

continueWhile

 final Task<Void> continueWhile(Callable<Boolean> predicate, Continuation<Void, Task<Void>> continuation, CancellationToken ct)
Continues a task with the equivalent of a Task-based while loop, where the body of the loop is a task continuation.

continueWhile

 final Task<Void> continueWhile(Callable<Boolean> predicate, Continuation<Void, Task<Void>> continuation, Executor executor, CancellationToken ct)
Continues a task with the equivalent of a Task-based while loop, where the body of the loop is a task continuation.

continueWith

 final <TContinuationResult extends Any> Task<TContinuationResult> continueWith(Continuation<TResult, TContinuationResult> continuation, Executor executor)
Adds a continuation that will be scheduled using the executor, returning a new task that completes after the continuation has finished running. This allows the continuation to be scheduled on different thread.

continueWith

 final <TContinuationResult extends Any> Task<TContinuationResult> continueWith(Continuation<TResult, TContinuationResult> continuation, Executor executor, CancellationToken ct)
Adds a continuation that will be scheduled using the executor, returning a new task that completes after the continuation has finished running. This allows the continuation to be scheduled on different thread.

continueWith

 final <TContinuationResult extends Any> Task<TContinuationResult> continueWith(Continuation<TResult, TContinuationResult> continuation)
Adds a synchronous continuation to this task, returning a new task that completes after the continuation has finished running.

continueWith

 final <TContinuationResult extends Any> Task<TContinuationResult> continueWith(Continuation<TResult, TContinuationResult> continuation, CancellationToken ct)
Adds a synchronous continuation to this task, returning a new task that completes after the continuation has finished running.

continueWithTask

 final <TContinuationResult extends Any> Task<TContinuationResult> continueWithTask(Continuation<TResult, Task<TContinuationResult>> continuation, Executor executor)
Adds an Task-based continuation to this task that will be scheduled using the executor, returning a new task that completes after the task returned by the continuation has completed.

continueWithTask

 final <TContinuationResult extends Any> Task<TContinuationResult> continueWithTask(Continuation<TResult, Task<TContinuationResult>> continuation, Executor executor, CancellationToken ct)
Adds an Task-based continuation to this task that will be scheduled using the executor, returning a new task that completes after the task returned by the continuation has completed.

continueWithTask

 final <TContinuationResult extends Any> Task<TContinuationResult> continueWithTask(Continuation<TResult, Task<TContinuationResult>> continuation)
Adds an asynchronous continuation to this task, returning a new task that completes after the task returned by the continuation has completed.

continueWithTask

 final <TContinuationResult extends Any> Task<TContinuationResult> continueWithTask(Continuation<TResult, Task<TContinuationResult>> continuation, CancellationToken ct)
Adds an asynchronous continuation to this task, returning a new task that completes after the task returned by the continuation has completed.

onSuccess

 final <TContinuationResult extends Any> Task<TContinuationResult> onSuccess(Continuation<TResult, TContinuationResult> continuation, Executor executor)
Runs a continuation when a task completes successfully, forwarding along Exception or cancellation.

onSuccess

 final <TContinuationResult extends Any> Task<TContinuationResult> onSuccess(Continuation<TResult, TContinuationResult> continuation, Executor executor, CancellationToken ct)
Runs a continuation when a task completes successfully, forwarding along Exception or cancellation.

onSuccess

 final <TContinuationResult extends Any> Task<TContinuationResult> onSuccess(Continuation<TResult, TContinuationResult> continuation)
Runs a continuation when a task completes successfully, forwarding along Exceptions or cancellation.

onSuccess

 final <TContinuationResult extends Any> Task<TContinuationResult> onSuccess(Continuation<TResult, TContinuationResult> continuation, CancellationToken ct)
Runs a continuation when a task completes successfully, forwarding along Exceptions or cancellation.

onSuccessTask

 final <TContinuationResult extends Any> Task<TContinuationResult> onSuccessTask(Continuation<TResult, Task<TContinuationResult>> continuation, Executor executor)
Runs a continuation when a task completes successfully, forwarding along Exceptions or cancellation.

onSuccessTask

 final <TContinuationResult extends Any> Task<TContinuationResult> onSuccessTask(Continuation<TResult, Task<TContinuationResult>> continuation, Executor executor, CancellationToken ct)
Runs a continuation when a task completes successfully, forwarding along Exceptions or cancellation.

onSuccessTask

 final <TContinuationResult extends Any> Task<TContinuationResult> onSuccessTask(Continuation<TResult, Task<TContinuationResult>> continuation)
Runs a continuation when a task completes successfully, forwarding along [ ]s or cancellation.

onSuccessTask

 final <TContinuationResult extends Any> Task<TContinuationResult> onSuccessTask(Continuation<TResult, Task<TContinuationResult>> continuation, CancellationToken ct)
Runs a continuation when a task completes successfully, forwarding along [ ]s or cancellation.

trySetCancelled

 final BooleantrySetCancelled()
Sets the cancelled flag on the Task if the Task hasn't already been completed.

trySetResult

 final BooleantrySetResult(TResult result)
Sets the result on the Task if the Task hasn't already been completed.

trySetError

 final BooleantrySetError(Exception error)
Sets the error on the Task if the Task hasn't already been completed.