diff options
| author | 2011-12-05 14:50:54 -0800 | |
|---|---|---|
| committer | 2011-12-05 14:50:54 -0800 | |
| commit | fe0d3523a52d7f05d54cbf917670d808e0765bb2 (patch) | |
| tree | 04f110e85fc8c6895793afad4e23e4ad27222ce3 | |
| parent | 714e0a6d54fd9f61b140a3b069f5010e1a93c0f6 (diff) | |
| parent | 657f51371cc631a82a8d30cd4a796c48077d474b (diff) | |
Merge "Make sure onPostExecute() is never called after cancel() Bug #5651553"
| -rw-r--r-- | core/java/android/os/AsyncTask.java | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/core/java/android/os/AsyncTask.java b/core/java/android/os/AsyncTask.java index 9dea4c43b699..5e9abb7ba612 100644 --- a/core/java/android/os/AsyncTask.java +++ b/core/java/android/os/AsyncTask.java @@ -195,6 +195,7 @@ public abstract class AsyncTask<Params, Progress, Result> { private volatile Status mStatus = Status.PENDING; + private final AtomicBoolean mCancelled = new AtomicBoolean(); private final AtomicBoolean mTaskInvoked = new AtomicBoolean(); private static class SerialExecutor implements Executor { @@ -261,6 +262,7 @@ public abstract class AsyncTask<Params, Progress, Result> { mTaskInvoked.set(true); Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); + //noinspection unchecked return postResult(doInBackground(mParams)); } }; @@ -269,9 +271,7 @@ public abstract class AsyncTask<Params, Progress, Result> { @Override protected void done() { try { - final Result result = get(); - - postResultIfNotInvoked(result); + postResultIfNotInvoked(get()); } catch (InterruptedException e) { android.util.Log.w(LOG_TAG, e); } catch (ExecutionException e) { @@ -295,6 +295,7 @@ public abstract class AsyncTask<Params, Progress, Result> { } private Result postResult(Result result) { + @SuppressWarnings("unchecked") Message message = sHandler.obtainMessage(MESSAGE_POST_RESULT, new AsyncTaskResult<Result>(this, result)); message.sendToTarget(); @@ -411,7 +412,7 @@ public abstract class AsyncTask<Params, Progress, Result> { * @see #cancel(boolean) */ public final boolean isCancelled() { - return mFuture.isCancelled(); + return mCancelled.get(); } /** @@ -444,6 +445,7 @@ public abstract class AsyncTask<Params, Progress, Result> { * @see #onCancelled(Object) */ public final boolean cancel(boolean mayInterruptIfRunning) { + mCancelled.set(true); return mFuture.cancel(mayInterruptIfRunning); } |