How can i use one HttpURLConnection download many pictures from one website?
My app should download many pictures from one website,the number is more than 200.So if i put this below code in a for(int i = 0; i++ ; i < 200),it looks not nice,the connection should connect and disconnect every time.
So anybody have some good suggestions?
URL imageUrl = new URL(url);
conn = (HttpURLConnection)(imageUrl.openConnection());
conn.connect();
InputStream is = conn.getInputStream();
BitmapFactory.Options ops = new BitmapFactory.Options();
ops.inSampleSize = 开发者_如何学GoinSample;
bitmap = BitmapFactory.decodeStream(is, null, ops);
is.close();
conn.disconnect();
URLConnection pooling happens behind the scenes. You don't have to worry about it yourself.
Since each image have a separate url, connection have to open and closed. There are no alternatives for this code.
精彩评论