Android : Multiple Requests in Parallel

on Saturday, September 13, 2014


I have some JSON resources like below


http://example.com?page=1


http://example.com?page=2


. . .


http://example.com?page=20


I am using AsyncTask and requesting each page within my OnPostExecute method and calling doinBackground method of the same class;



@Override
protected void onPostExecute(ArrayList<MyClass> result) {
currentPage++;
if(currentPage == 21){
Intent intent = new Intent(getApplicationContext(), MyActivity.class);
intent.putParcelableArrayListExtra("List", result);
startActivity(intent);

}
else{
new DownloadInfoTask().execute(this.URL + "&page=" + currentPage);
}
}


It seems working for me so far even if each thread is waiting for the previous ones completion. My question is would it be a better approach if i use parallel execution for consuming these kinds of resources and how can i implement parallel execution to my problem?


0 comments:

Post a Comment