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 6917947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:47:47+00:00 2026-05-27T09:47:47+00:00

In my activity, I download several images and then display them by adding each

  • 0

In my activity, I download several images and then display them by adding each one of them on my main layout. I tried these 3 approaches but each time my progress dialog freezes until the images are loaded:

1st approach: Using an async task: I download the images on doInBackground() and add them to the main layout onPostExecute ()

2nd: The same as above, but I add each one of the images onProgressUpdate()

3rd: Using a handler and a thread

Each time the progress dialog freezes for a few seconds (actually the whole application freezes) until the images are downloaded and displayed on the screen.

I have been trying to fix this for a long time but nothing yet. Any ideas? Here’s a part of my code:

     protected Integer doInBackground(Void... params) {         
        //...
            try {
                //download images
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            if (!loadTask.isCancelled()) {                  
                //Display images        
                int length=imageList.size();        

                for (i=0; i<length; i++) {                      
                    publishProgress(i);                     
                }
            }               

        return 1;                       
    }

  protected void onProgressUpdate(Integer... a) {
        //interaction with UI thread
        int i = a[0];
        ImageView im = new ImageView (MyActivity.this);
        im.setImageBitmap(getRemoteImage(imageUrl));
        im.setLayoutParams(Params);
        im.setAdjustViewBounds(true);
        im.setPadding(px2, px2, px2, px2);
        im.setOnClickListener(new OnClickListener() {
              public void onClick(View v) {
                  //...
              }               
        });
    }
  • 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-27T09:47:47+00:00Added an answer on May 27, 2026 at 9:47 am
    im.setImageBitmap(getRemoteImage(imageUrl));
    

    If getRemoteImage() does what it’s name and argument suggests (downloading an image from the web), then this line is your problem, since it’s executed in onProgressUpdate().

    onProgressUpdate() runs in the UI-thread and not in the background thread, it’s supposed to do UI work when the progress changed. When you download your images here, you block the UI thread for a the amount of time it takes for the download of an image to finish. Since you loop over all images, it will hold your UI thread until all your images are downloaded.

    Rather run the download in doInBackground() (your comment at the top of the method suggests that you already do that) and pass the downloaded image over to onProgressUpdate via the argument that publishProgress() takes.

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

Sidebar

Related Questions

In my app, the activity starts a thread which download images from server. There
I have one activity which download data from the web. In middle of the
In my main Activity of the app, I download some user data at the
In an activity A I download several files from the server to my device.
I need to download by program an .apk file then launching its activity. The
Main Activity: private Button btnSubmit; private DataSource mDataSource; private Context mContext; @Override public void
An Activity occurs at a location on a specific date, but each activity may
I use the DownloadManager to download a xml file from a URL. Then I
I'm trying to download a website source code and display it in a textbox
I've to automate a file download activity from a website (similar to, let's say,

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.