1

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.

1 Answer 1

1
 as my AsyncTask class returns a single "response" string.

=> It is not true. Because AsyncTask can return ArrayList as well other than a string only.

You should check the AsyncTask's Generic type

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer. Any help about how to go about implementing this? Or a link maybe?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.