user3458541
user3458541

Reputation: 104

How to run more than one service simultaneously in android without any conflict?

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

}

Upvotes: 0

Views: 134

Answers (1)

Chetak Bhimani
Chetak Bhimani

Reputation: 459

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);
}

Upvotes: 1

Related Questions