I'm using the following class (AsyncTask) to retrieve info from 8 different URL's. I want to store the retrieved data into an array of 8 elements (one for each URL I get data from).
private class getDataClass extends AsyncTask<String, Void, String>{
protected String doInBackground(String...urls){
String response = "";
for(String url : urls){
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
try{
HttpResponse execute = client.execute(httpGet);
InputStream content = execute.getEntity().getContent();
BufferedReader buffer = new BufferedReader(new InputStreamReader(content));
String s = "";
while((s = buffer.readLine()) != null){
response += s;
}
}catch(Exception e){
e.printStackTrace();
}
}
return response;
}
protected void onPostExecute(String result){
Resources.descriptionArray[descriptionArray_Counter] = Html.fromHtml(result).toString();
descriptionArray_Counter++;
}
And calling it like this:
getDataClass getData = new getDataClass();
getData.execute(description_links);
The problem I'm obviously getting is that all the info is stored into array[0], as my AsyncTask class returns a single "response" string.
What I'd like to know, since I haven't found many examples of this is what would be a more elegant way to do this and how would other, more experienced coders go about this.
Thanks a lot for taking the time to answer.