com.google.android.gms.tasks.Continuation<TResult, TContinuationResult> |
A function that is called to continue execution after completion of a Task
.
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns the result of applying this Continuation to
task . |
Returns the result of applying this Continuation to task
.
To propagate failure from the completed Task call getResult()
and allow the
RuntimeExecutionException
to propagate. The RuntimeExecutionException will be
unwrapped such that the Task returned by continueWith(Continuation)
or
continueWithTask(Continuation)
fails with the original exception.
To suppress specific failures call getResult(Class)
and catch the exception
types of interest:
task.continueWith(new Continuation<String, String>() { @Override public String then(Task<String> task) { try { return task.getResult(IOException.class); } catch (FileNotFoundException e) { return "Not found"; } catch (IOException e) { return "Read failed"; } } }
To suppress all failures guard any calls to getResult()
with
isSuccessful()
:
task.continueWith(new Continuation<String, String>() { @Override public String then(Task<String> task) { if (task.isSuccessful()) { return task.getResult(); } else { return DEFAULT_VALUE; } } }
Parameters | |
---|---|
task |
Task :
the completed Task. Never null |
Returns | |
---|---|
TContinuationResult |
Throws | |
---|---|
Exception |
if the result couldn't be produced |