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

  • Home
  • SEARCH
  • 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 8450741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:03:19+00:00 2026-06-10T11:03:19+00:00

I want to show a progressbar downloading a bitmap: public static Bitmap getBitmapFromURL(String src)

  • 0

I want to show a progressbar downloading a bitmap:

    public static Bitmap getBitmapFromURL(String src) {
    try {
        URL url = new URL(src);
        HttpURLConnection connection = (HttpURLConnection) url
                .openConnection();
        connection.setDoInput(true);
        connection.connect();

        InputStream input = connection.getInputStream();

        int fileLength = connection.getContentLength();

        // download the file

        byte data[] = new byte[1024];
        long total = 0;
        int count;
        while ((count = input.read(data)) != -1) {
            total += count;
            // publishing the progress....
            progressDialog.setProgress((int) (total * 100 / fileLength));
            Log.i("progre+ss", (int) (total * 100 / fileLength) + " ");
        }

        Bitmap myBitmap = BitmapFactory.decodeStream(input);
        return myBitmap;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

which is initialised with:

    private void openprogresdialog() {
    // TODO Auto-generated method stub
    progressDialog = new ProgressDialog(PrMapGen.this);
    progressDialog.setMessage("Generating File...");
    progressDialog.setCancelable(false);
    progressDialog.setIndeterminate(false);
    progressDialog.setMax(100);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progressDialog.show();

    new Thread() {
        public void run() {
            try {
                generatePrMap(DataArray,
                        getIntent().getExtras().getString("project"));

            } catch (Exception e) {
            }
            progressDialog.dismiss();
            projdata.close();
            finish();
        }
    }.start();
}

My problem is the following:

when I use the while loop to update the progressbar, no image is returned, when I delete the while loop the bitmap is returned successfuly.

Why???

thanks in advance

  • 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-06-10T11:03:21+00:00Added an answer on June 10, 2026 at 11:03 am

    Here is a tip to do it the easy way.

    Declare an AsyncTask.

    Put your code to download the image in the doInBackgroud() and set the progressBar inside onUpdateProgress().

    You can check this question too.

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

Sidebar

Related Questions

Possible Duplicate: AsyncTask block UI threat and show progressbar with delay I want to
I want to show my application user a progressbar for following actions: when they
I want to show my progressbar in the center of the screen when a
I want to show a ProgressBar inside a normal jface Dialog at the start
I want to show a progress bar while downloading a file from the web
In my application i'm downloading a video file. I want to show the progress
I want to show progress with jquery ui progress bar when an ajax request
I want show an information page after success db opartions. And after the info
I want show annotation view (above one of my pin) after load map. For
hii I want show a pop up Dialog box when i click on to

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.