I have created android application which has images which I am decoding from URL. I am getting following error while decoding URL into Bitmap. Its occurring on random phones. What is best case the error doesnt occur.
Following is error:
Caused by: java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeStream(BitmapFactory.java)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:663)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:735)
This is code i used to decode image url:
Bitmap mIcon11 = null;
String filePath = imageURL;
InputStream in = null;
in = new java.net.URL(filePath).openStream();
BitmapFactory.Options o = new BitmapFactory.Options();
o.inSampleSize = 8;
o.inJustDecodeBounds = true;
o.inPurgeable = true;
mIcon11 = BitmapFactory.decodeStream(in);
return mIcon11;
I don't want it to crash in any case.
Please help