Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6206013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:22:25+00:00 2026-05-24T05:22:25+00:00

I have an app in android and I’m trying to retrieve some pictures from

  • 0

I have an app in android and I’m trying to retrieve some pictures from the internet using an AsyncTask thread.
The thing is that I’m retrieving this pictures in a loop so for each index I’m launching a new AsyncTask thread.Each thread returnes a picture(imageView).

And here is my problem:

The threads launched return the pictures asynchorounsly so when I’m trying to acces the List that stores these images I get ArrayIndexOutofBounds.

This is my code:

for(int i=0;i<friends.size();i++)
                    {
            getUserPic(friends.get(i).getId());
                    }

This is the getUserPic method:

  public void getUserPic(String userID){

        imageURL = "http://graph.facebook.com/"+userID+"/picture?type=small";
    new Task().execute(new String[] {imageURL});

    }

And here is the thread:

 private class Task extends AsyncTask<String, Void, Bitmap>{

        @Override
        public Bitmap doInBackground(String...arg0){


            DefaultHttpClient client = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet(arg0[0]);
            try{
                HttpResponse execute = client.execute(httpGet);
                InputStream content = execute.getEntity().getContent();

        profilePicBitmap=BitmapFactory.decodeStream(content);


            }
           catch (MalformedURLException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
          return profilePicBitmap;

        }
        @Override
           public void onPostExecute(Bitmap result) {
                imageView.setImageBitmap(result);
                arrayImageView.add(imageView);
            }
}

So what I wanna do is something like:

  List<ImageView> arrayImageView=new ArrayList<ImageView>();



    for(i....)

    {
 arrayImageView[i]=getUserPic(...);
     }

 public ImageView getUserPic(String userID){

            imageURL = "http://graph.facebook.com/"+userID+"/picture?type=small";
        new Task().execute(new String[] {imageURL});
return ImageView;

        }

I mean each ImageView return by the AsyncTask thread to be returned also by the getUserPic method.So would be more easily for me to keep track of them.

Question:How do I proceed so the pictured returned by AsynTask to be also the variable that getUserPic() returns.

I hope u get what I mean.Thx

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:22:26+00:00Added an answer on May 24, 2026 at 5:22 am

    If i’m right you can do this..

     for(i....)
    
        {
     arrayImageView[i]=getUserPic(...);
         }
    
     public ImageView getUserPic(String userID){
    
                imageURL = "http://graph.facebook.com/"+userID+"/picture?type=small";
            new Task().execute(new String[] {imageURL});
    progressDialog = ProgressDialog.show(context, "", "Please Wait....");//**progressDialog** an instance variable
    
    return ImageView;
    
            }
    

    and in postExecute dismiss this dialog.. I suggest this because at this moment the UI thread will be blocked and u can make sure your imageView is initialised with some value in postExecute() and can be returned when dialog is dismissed and the UI thread resumes..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app in android that in a different thread from the UI(which
I have an app in android where I'm returning some pictures from facebook pages.I
I have an Android app, that is using the SIM Toolkit. The application has
I have an android app that I am trying to launch and it gives
I have android app that talks to server and syncs some data int SQLite
I have PhoneGap app in Android using jQuery. Sometimes I need to upload some
I have an app in android which retrieve a picture from http page.I'm asking
I have an app in android in which I return some data from facebook
I have an app that runs fine using android phonegap 1.2 and jqm 1.0,
I have android app . i should pass the data from android to web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.