Executing Two Asynctask In In Two Different Classes
Solution 1:
After Android API 11, AsyncTask
s started to run on serial executor by default, that means that only one task is running at a time. To get the behavior of prior to API 11, which is running on ThreadPoolExecutor
, you'll need to specify it in the code like this:
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.HONEYCOMB) {
myTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
else {
myTask.execute();
}
Please take a look here for more information: http://commonsware.com/blog/2012/04/20/asynctask-threading-regression-confirmed.html
Good luck!
P.S. It's not recommended to use AsyncTask
for an infinite thread, AsyncTask
purpose is to do a Task on the background, not to run forever, so if you want an infinite thread, I think you should create it as a Thread
and not as an AsyncTask
.
Solution 2:
You asynctasks are in two different activities. Only one activity is active at any time.
Solution 3:
Both classes extend Activity and only one of them is running at the same time. If you want a task to be execute longer than the lifetime of an activity, you have to wrap it into an Service
Post a Comment for "Executing Two Asynctask In In Two Different Classes"