I am using following code snippet to load url to bitmap in for loop. It gives null value to bitmap sometimes.So what could be the proper solution to get bitmap value for each loop??
for (int i = 0; i < len; i++) {
String url = "image url"+i;
try {
URL url2 = new URL(url);
InputStream inputStream = url2.openConnection()
.getInputStream();
bitmap = BitmapFactory.decodeStream(inputStream);
Log.i("@@@@@@@@@@ bitmap", "" + bitmap);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
InputStream may have problems when the network connection is not stable,which leads to null return value for BitmapFactory.decodeStream().I had also encountered this problem.
Algo has created a FlushedInputStream class, which solves my problem, it may help you
original post : Android decoder->decode returned false for Bitmap download