I'm trying to run two AsyncTasks at the same time. However, only the first gets executed. And no data returned from second service. When refresh it second time I get data from service hoe to resolve the issue?? Here is my code

new MyClass().execute("Main");

> Class is

private class MyClass extends AsyncTask<Object, Void, String> {

> here i am using pre post and do in background methods

}
有帮助吗?

解决方案

This allows for parallel execution on all android versions with API 4+ (Android 1.6+):

@TargetApi(Build.VERSION_CODES.HONEYCOMB) // API 11

void startMyTask(AsyncTask asyncTask) {
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
        asyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
    else
        asyncTask.execute(params);
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top