Frage

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

}
War es hilfreich?

Lösung

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);
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top