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
This commit is contained in:
@@ -298,12 +298,16 @@ public abstract class AsyncTask<Params, Progress, Result> {
|
|||||||
mWorker = new WorkerRunnable<Params, Result>() {
|
mWorker = new WorkerRunnable<Params, Result>() {
|
||||||
public Result call() throws Exception {
|
public Result call() throws Exception {
|
||||||
mTaskInvoked.set(true);
|
mTaskInvoked.set(true);
|
||||||
|
Result result = null;
|
||||||
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
|
try {
|
||||||
//noinspection unchecked
|
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
|
||||||
Result result = doInBackground(mParams);
|
//noinspection unchecked
|
||||||
Binder.flushPendingCommands();
|
result = doInBackground(mParams);
|
||||||
return postResult(result);
|
Binder.flushPendingCommands();
|
||||||
|
} finally {
|
||||||
|
postResult(result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user