Skip to content Skip to sidebar Skip to footer

Android Bitmap Out-of-memory Error After Getting Same Image Twice In A Row

I have a program that is supposed to grab an image from a user's gallery and then display the image in a subsequent activity. As part of my testing, I try to do the operation twice

Solution 1:

Recycle the currently loaded bitmap image when the user presses the back button and goes of a different image

myImage.recycle();

Solution 2:

You should prepare the image for display by loading it with options.inJustDecodeBounds = true; and then adjusting the samplesize.

See: http://developer.android.com/training/displaying-bitmaps/

Apart from that, are you calling bitmap.recycle() when you no longer need the bitmap? The first could still be in memory when you load the second, causing the error.

Post a Comment for "Android Bitmap Out-of-memory Error After Getting Same Image Twice In A Row"