diff options
| author | Tony Mantler <nicoya@google.com> | 2016-08-05 14:08:06 -0700 |
|---|---|---|
| committer | Tony Mantler <nicoya@google.com> | 2016-08-05 22:03:45 +0000 |
| commit | 78a8e9d2939dcb7be3d3a656c6ac630f17d73854 (patch) | |
| tree | 9f2682cb846926cf08ed0631fad7d9002f13bf1b /core/java/android/os/AsyncTask.java | |
| parent | ba8f3d03ac43800c5b962d6559b592d6adb5b678 (diff) | |
Fix AsyncTask to handle exceptions in doInBackground
When cancelling, the exception will be eaten by FutureTask, but
onCancelled would end up never being called due to the exception
causing the code to skip calling postResult.
b/30304893
Change-Id: I47d859d9ef77245889816b2b6e10bb380bc4979b
Diffstat (limited to 'core/java/android/os/AsyncTask.java')
| -rw-r--r-- | core/java/android/os/AsyncTask.java | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/core/java/android/os/AsyncTask.java b/core/java/android/os/AsyncTask.java index 63f39c59b1b7..5d022b813a24 100644 --- a/core/java/android/os/AsyncTask.java +++ b/core/java/android/os/AsyncTask.java @@ -298,12 +298,16 @@ public abstract class AsyncTask<Params, Progress, Result> { mWorker = new WorkerRunnable<Params, Result>() { public Result call() throws Exception { mTaskInvoked.set(true); - - Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); - //noinspection unchecked - Result result = doInBackground(mParams); - Binder.flushPendingCommands(); - return postResult(result); + Result result = null; + try { + Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); + //noinspection unchecked + result = doInBackground(mParams); + Binder.flushPendingCommands(); + } finally { + postResult(result); + } + return result; } }; |
