I work for my license project, and one part consist in an android client. All was ok, until I upgraded my phone to Android 4.0.4.
So, I have one AsyncTask. It looks like this:
public class TestTask extends AsyncTask<Context, Integer, Long> {
@Override
protected Long doInBackground(Context... params) {
for (int i = 0; i < 10; i++) {
System.out.println("nothing-" + i);
if (i == 5) {
TestTask2 testTask2 = new TestTask2();
testTask2.execute(null);
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return null;
}
}
This task wait 5 seconds, than it calls another async task, TestTask2.
public class TestTask2 extends AsyncTask<Context, Integer, Long> {
@Override
protected Long doInBackground(Context... params) {
System.out.println("task 2 in action");
return null;
}
}
In android 4.0.3 or lower, the output is:
nothing-0 nothing-1 nothing-2 nothing-3 nothing-4 nothing-5
task 2 in action
nothing-6 nothing-7 nothing-8 nothing-9
When I upgraded to 4.0.4, the second task doesn’t start until the first finished its job.
nothing-0 nothing-1 nothing-2 nothing-3 nothing-4 nothing-5 nothing-6 nothing-7 nothing-8 nothing-9
task 2 in action
Is there any thread policy in android 4.0.4, or something else? what could be the problem?
Thanks for the question. Apparently the default behavior has changed:
https://groups.google.com/d/msg/android-developers/8M0RTFfO7-M/JZSHiOz9bPgJ
You can get the old behavior by changing this:
to this: