I'm getting a lot of these exceptions from users: java.lang.OutOfMemoryError: bitmap size exceeds VM budget - but i'm unable to reproduce the problem on the emulator.
I'm using this as my ImageDownloader http://code.google.com/p/android-imagedownloader/source/browse/trunk/src/com/example/android/imagedownloader/ImageDownloader.java#185 and the problem occurs on line 185 when trying to decode the image.
There is a lot of other questions here on stackoverflow, regarding this error, but none that fits my specific case. The solution in this question could work: https://stackoverflow.com/a/823966 but i can't seem to get it to work.
Here is what i changed in my ImageDownloader:
final HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream inputStream = null;
try {
inputStream = entity.getContent();
// return BitmapFactory.decodeStream(inputStream);
// Bug on slow connections, fixed in future release.
FlushedInputStream flushedStream = new FlushedInputStream(inputStream);
// Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(flushedStream, null, o);
Log.d(LOG_TAG, "decodeStream - outWidth=" + o.outWidth + " outHeight=" + o.outHeight);
// The new size we want to scale to
final int REQUIRED_SIZE = 70;
// Find the correct scale value. It should be the power of
// 2.
int scale = 1;
while (o.outWidth / scale / 2 >= REQUIRED_SIZE && o.outHeight / scale / 2 >= REQUIRED_SIZE)
scale *= 2;
// Decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
return BitmapFactory.decodeStream(flushedStream, null, o2);
} finally {
if (inputStream != null) {
inputStream.close();
}
entity.consumeContent();
}
}
It fails when calling decodeStream() the second time. Error is SkImageDecoder::Factory returned null. I figured maybe the inputStream is closed or not available on the second call, so i then tried to use BufferedHttpEntity in the first line above, but with no luck.
Can someone guide me towards the right direction? Thanks.