I need to allow multiple AsyncTask to be running at the same time . This my my AsyncTask :
private void callAPI(String user_id) {
new AsyncTask<Void, Void, String>() {
protected String doInBackground(Void... parameters) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("user_id", user_id));
return api.post("", params);
}//end doInBackground
protected void onPostExecute(String result) {
Log.i(TAG + "POST() => " + result);
}//end onPostExecute
}.execute(); //end AsyncTask
}
I saw an answer at running-multiple-asynctasks but I don't know how to use it . How can I implement the code below within my AsyncTask :
@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);
}
Create call from AsynTask and call class from MainActivity synchronously :
From your MainActivity onCreate():
Use this class if you want to execute concurrently Asynctask. Found this class and its working for me.
Asynctask
Hope it helps you!