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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:46:47+00:00 2026-05-26T11:46:47+00:00

I am making an android application that gets updated. For this I need a

  • 0

I am making an android application that gets updated. For this I need a simple function that can download a file and show the current progress in a ProgressDialog. I know how to do the download the file, but I’m not sure how to display the current progress.I am using the following method for downloading images.

public Bitmap DownloadFile(String url){
URL myFileUrl;
Bitmap bitmap=null;
try {
myFileUrl = new URL(imageUrl);
    HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();
    conn.setDoInput(true);
    conn.setConnectTimeout(10000);
    conn.setReadTimeout(10000);
    conn.connect();
    InputStream is = conn.getInputStream();
    bmImg = BitmapFactory.decodeStream(is);
    bitmap = BitmapFactory.decodeStream((InputStream) new URL(  
         imageUrl).getContent()); 
    bitmap = Bitmap.createScaledBitmap(bitmap,80 , 80, true);
    System.out.println("name of butmap"+bitmap.toString());

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bitmap;

}

And following is my async task class :

    public class BackgroundAsyncTask extends AsyncTask<String, Integer, Bitmap> {

   int myProgress;

   @Override

    protected void onPostExecute(Bitmap result) {
    dialog.dismiss();
    iv.setVisibility(View.VISIBLE);
    iv.setImageBitmap(result);
    System.out.println("bbbbbbbbb");
    System.out.println("post execute");
    }

@Override
protected void onPreExecute() {
    System.out.println("pre execute");
    dialog = ProgressDialog.show(ProfileNormalUserPhotos.this, "Loading...", "Please wait...");

}

@Override
protected Bitmap doInBackground(String...paths) {
    System.out.println(imageUrl+"  imageurl");
    return DownloadFile(imageUrl);

    }
@Override
protected void onProgressUpdate(Integer... values) {
    // TODO Auto-generated method stub
        progressBar.setProgress(values[0]);
}

}

and i am calling the method in the following adapter class :

    public class ImageAdapter extends BaseAdapter {  
       Context mContext;
   public String[] stringOnTextView;

     public ImageAdapter(Context c) {  
       mContext = c;  
     }  

public ImageAdapter(Context Context,
    String[] stringOnTextView) {
    this.mContext=Context;
    this.stringOnTextView=stringOnTextView;
}

public int getCount() {  
      return stringOnTextView.length;  
     }  


public Object getItem(int position) {  
      return null;  
     }  

     public long getItemId(int position) {  
      return position;  
     }  


     public View getView(int position, View convertView, ViewGroup parent) {
         View v = null;
        if(convertView==null){

            try{

            {
                  LayoutInflater li = getLayoutInflater();
                  v = li.inflate(R.layout.icon, null);
                  TextView tv = (TextView)v.findViewById(R.id.text);
                  tv.setText("Profile Image "+(position+1));
                   iv= (ImageView)v.findViewById(R.id.image);

                   imageUrl = "http://ondamove.it/English/images/users/";
                  imageUrl=imageUrl+stringOnTextView[position];
                   new BackgroundAsyncTask().execute(imageUrl);


                   }
           }catch (Exception e) {
            e.printStackTrace();
            System.out.println(e);
        }
        }
        else
        {
            try{
            v = convertView;}
            catch(Exception e){
                System.out.println(e);
            }
        }
        return v;
    }
}

I need to download 9 images but the problem i am facing is that it only shows the last image and progress dialog goes into infinite loop.

Can anyone tell me over how to resolve thios issue.

Thanks

  • 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-26T11:46:48+00:00Added an answer on May 26, 2026 at 11:46 am

    I got the solution by working on it and the following should be the solution for this:

    class DownloadFileAsync extends AsyncTask<String, String, String>
    {
        int count;
        URL myFileUrl;
        ImageView imageview;
        Bitmap bp;
    
        public DownloadFileAsync(ImageView iv, URL uu)
        {
            this.imageview = iv;
            this.myFileUrl = uu;
        }
    
        @Override
        protected void onPreExecute()
        {
            super.onPreExecute();
            showDialog(DIALOG_DOWNLOAD_PROGRESS);
        }
    
        @Override
        protected String doInBackground(String... aurl)
        {
            for (int i = 0; i < aurl.length; i++)
                System.out.println("----------" + i + "------" + aurl[i]);
    
            try
            {
                HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();
                conn.setConnectTimeout(10000);
                conn.setReadTimeout(10000);
                conn.connect();
                InputStream is = conn.getInputStream();
                bmImg = BitmapFactory.decodeStream(is);
                bp = BitmapFactory.decodeStream((InputStream) (myFileUrl).getContent());
                bp = Bitmap.createScaledBitmap(bp, 70, 70, true);
    
            }
            catch (Exception e)
            {
                System.out.println(e);
                e.printstacktrace();
            }
    
            return null;
        }
    
        protected void onProgressUpdate(String... progress)
        {
            dialog.setProgress(Integer.parseInt(progress[0]));
        }
    
        @Override
        protected void onPostExecute(String unused)
        {
            try
            {
                imageview.setImageBitmap(bp);
                System.out.println("this is" + this);
                // dialog.dismiss();
                dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
    
            }
            catch (Exception e)
            {
                System.out.println(e);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making an Android application that reads an XML Internet. This application uses SAX
I am making an android application that will play an mp3 file once a
I'm in the process of making an Android application that creates a new file
I'm creating an android application that gets the current time in a different country/time-zone.
I'm making an android application that does DOM parsing on an xml file. I
So I'm making this android application, that needs to read data from user-provided CSV
I'm making in house application that download data via xml files from external server.
I'm trying to create an application that can use the android as a fax
So as of current I am making an Android application with multiple layout files
I'm making an application for Android that needs to react to when the device

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.