summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Romain Guy <romainguy@android.com> 2011-09-16 16:00:59 -0700
committer Romain Guy <romainguy@android.com> 2011-09-16 16:00:59 -0700
commit6dafefb0f44c4e57384e2ec3e08fefac5cc7e071 (patch)
tree5431629b4b077cbd96fa7f423d110966a402d6bf
parent7c963167288d1fb186a98b1232aa2ac571e9ff09 (diff)
Forces AsyncTask to use the main looper
Bug #5333924 This might break applications trying to use AsyncTask on a looper that is not the main thread, but such apps would already have issues (AsyncTask has a single static handler and attempting to use AsyncTask outside of the main thread would likely result in weird threading issues in other parts of the app.) Change-Id: Ibbf480627fc7b91326a27d4f5e5af49e8c5b5115
-rw-r--r--core/java/android/os/AsyncTask.java8
1 files changed, 7 insertions, 1 deletions
diff --git a/core/java/android/os/AsyncTask.java b/core/java/android/os/AsyncTask.java
index 64bba54b2cee..6a512a96f373 100644
--- a/core/java/android/os/AsyncTask.java
+++ b/core/java/android/os/AsyncTask.java
@@ -237,6 +237,7 @@ public abstract class AsyncTask<Params, Progress, Result> {
/** @hide Used to force static handler to be created. */
public static void init() {
+ // TODO: This doesn't do anything, we should get rid of it
sHandler.getLooper();
}
@@ -254,6 +255,7 @@ public abstract class AsyncTask<Params, Progress, Result> {
mTaskInvoked.set(true);
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
+ //noinspection unchecked
return postResult(doInBackground(mParams));
}
};
@@ -288,7 +290,7 @@ public abstract class AsyncTask<Params, Progress, Result> {
}
private Result postResult(Result result) {
- Message message = sHandler.obtainMessage(MESSAGE_POST_RESULT,
+ @SuppressWarnings({"unchecked"}) Message message = sHandler.obtainMessage(MESSAGE_POST_RESULT,
new AsyncTaskResult<Result>(this, result));
message.sendToTarget();
return result;
@@ -598,6 +600,10 @@ public abstract class AsyncTask<Params, Progress, Result> {
}
private static class InternalHandler extends Handler {
+ InternalHandler() {
+ super(Looper.getMainLooper());
+ }
+
@SuppressWarnings({"unchecked", "RawUseOfParameterizedType"})
@Override
public void handleMessage(Message msg) {