Continuation

public interfaceContinuation<TResult, TContinuationResult>

A function that is called to continue execution after completion of aTask.

Parameters
<TResult>

the Task's result type

<TContinuationResult>

the Continuation's result type

Summary

Public methods

abstract TContinuationResult
then(@NonNullTask<TResult> task)

Returns the result of applying this Continuation totask.

Public methods

then

abstract TContinuationResultthen(@NonNullTask<TResult> task)

Returns the result of applying this Continuation totask.

To propagate failure from the completed Task callgetResultand allow theRuntimeExecutionExceptionto propagate. The RuntimeExecutionException will be unwrapped such that the Task returned bycontinueWithorcontinueWithTaskfails with the original exception.

To suppress specific failures callgetResultand catch the exception types of interest:

task.continueWith(newContinuation<String,String>(){
@Override
publicStringthen(Task<String>task){
try{
returntask.getResult(IOException.class);
}catch(FileNotFoundExceptione){
return"Notfound";
}catch(IOExceptione){
return"Readfailed";
}
}
}

To suppress all failures guard any calls togetResultwithisSuccessful:

task.continueWith(newContinuation<String,String>(){
@Override
publicStringthen(Task<String>task){
if(task.isSuccessful()){
returntask.getResult();
}else{
returnDEFAULT_VALUE;
}
}
}
Parameters
@NonNullTask<TResult> task

the completed Task. Never null

Throws
java.lang.Exception

if the result couldn't be produced