diff --git a/src/android/Library/src/ImageFetcher.java b/src/android/Library/src/ImageFetcher.java index f2adc9a..88255bd 100644 --- a/src/android/Library/src/ImageFetcher.java +++ b/src/android/Library/src/ImageFetcher.java @@ -178,29 +178,34 @@ public class ImageFetcher { */ @Override protected Bitmap doInBackground(Integer... params) { - position = params[0]; - if (isCancelled()) { - return null; - } - Bitmap thumb = MediaStore.Images.Thumbnails.getThumbnail(mContext.getContentResolver(), position, 12345, - MediaStore.Images.Thumbnails.MINI_KIND, null); - if (isCancelled()) { - return null; - } - if (thumb == null) { - return null; - } else { - if (isCancelled()) { - return null; - } else { - if (rotate != 0) { - Matrix matrix = new Matrix(); - matrix.setRotate(rotate); - thumb = Bitmap.createBitmap(thumb, 0, 0, thumb.getWidth(), thumb.getHeight(), matrix, true); - } - return thumb; - } - } + try { + position = params[0]; + if (isCancelled()) { + return null; + } + Bitmap thumb = MediaStore.Images.Thumbnails.getThumbnail(mContext.getContentResolver(), position, 12345, + MediaStore.Images.Thumbnails.MINI_KIND, null); + if (isCancelled()) { + return null; + } + if (thumb == null) { + return null; + } else { + if (isCancelled()) { + return null; + } else { + if (rotate != 0) { + Matrix matrix = new Matrix(); + matrix.setRotate(rotate); + thumb = Bitmap.createBitmap(thumb, 0, 0, thumb.getWidth(), thumb.getHeight(), matrix, true); + } + return thumb; + } + } + }catch(OutOfMemoryError error) { + clearCache(); + return null; + } } @@ -362,8 +367,8 @@ public class ImageFetcher { * after a certain inactivity delay. */ public void clearCache() { - // sHardBitmapCache.clear(); - // sSoftBitmapCache.clear(); + sHardBitmapCache.clear(); + sSoftBitmapCache.clear(); } /**