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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:50:09+00:00 2026-06-14T18:50:09+00:00

In my app i’m using code like the following to download several images. Is

  • 0

In my app i’m using code like the following to download several images.
Is it High-Performance to do it like that or can I reuse the connection somehow?

   for(int i = 0; i < 100; i++){  
    URL url = new URL("http://www.android.com/image" + i + ".jpg");
           HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
           try {
             InputStream in = new BufferedInputStream(urlConnection.getInputStream());
             readStream(in);
            finally {
             urlConnection.disconnect();
           }
         }
}
  • 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-14T18:50:10+00:00Added an answer on June 14, 2026 at 6:50 pm

    You won’t really get any benefit from reuse of the HttpURLConnection.

    One thing that will greatly benefit your application is if you spend some time looking into Async Tasks, which will allow you to harness the power of multi threaded HTTP requests with callbacks to your main code.

    See:
    http://www.vogella.com/articles/AndroidPerformance/article.html
    for a good example of how Async Tasks can be utilised.

    A good starting point though is of course the Android Developers Blog, where they have an example for downloading an image from a server asynchronously, which will match your requirements nicely. With some adaptation you can have your application sending multiple asynchronous requests at once for good performance.

    The Google article can be found at:
    http://android-developers.blogspot.co.uk/2009/05/painless-threading.html

    The key area to look at is:

    public void onClick(View v) {
      new DownloadImageTask().execute("http://example.com/image.png");
    }
    
    private class DownloadImageTask extends AsyncTask {
         protected Bitmap doInBackground(String... urls) {
             return loadImageFromNetwork(urls[0]);
         }
    
         protected void onPostExecute(Bitmap result) {
             mImageView.setImageBitmap(result);
         }
     }
    

    The loadImageFromNetwork method is where the downloading takes place, and will be completely asynchronous away from your main UI thread.

    As a basic example, you could modify your application to call this like so:

    for(int i = 0; i < 100; i++){  
        new DownloadImageTask().execute("http://www.android.com/image" + i + ".jpg");
    }
    

    Though for an optimisation, I wouldn’t throw 100 requests out at once, maybe creating a Threaded queue system which will allow maybe 4 or 5 concurrent connections and then keep the rest coming through when another finishes by maintaining an ArrayList of pending requests to read off.

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

Sidebar

Related Questions

app link: http://itunes.apple.com/en/app/quick-tweet/id505987287?mt=12 How can i make something like that circle? is that a
The app I am working on is supporting android 2.3 upwards. As the download
My app is saving some images on the SD Card, in the AppImages directory
My app is slowed down by N+1 queries. I'm using the will_paginate gem with
My app must support iOS 3.1.2 But it looks like __weak, __block and __unsafe_unretained
My app uses LoadLibrary to load plugins at run-time and users can accidentally try
We're building an app, our first using Rails 3, and we're having to build
App is in prism/mvvm/mef and uses loading by attribute like StockTraderRI. My shell window
app.use(express.compiler({ src: __dirname + '/public', enable: ['less'] })); That's the line in my app.js
My app is crashing with the error code: SIGABRT. Ive done a ton of

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.