In my app I am fetching 4-5 bitmaps from url and I use them like a gallery.
if i switch images more than 6-10 times I am getting this error:
09-01 12:08:45.217: E/AndroidRuntime(350): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
09-01 12:08:45.217: E/AndroidRuntime(350): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
09-01 12:08:45.217: E/AndroidRuntime(350): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:459)
09-01 12:08:45.217: E/AndroidRuntime(350): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:515)
This is my code:
try {
bitmapResult = BitmapFactory.decodeStream((InputStream)new URL(url[newPage+1]).getContent());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
v.setImageBitmap(bitmapResult);
My question os this:
Will this happen only in emulator?
Morevoer, and more important. Will it me more efficient if using drawable insted? In that case I will convert my bitmap to drawable with code below and I will setImageresource. Do I have to "release" anything?
Drawable d = new BitmapDrawable(getResources(),bitmapResult);