In last line I get a crash:
InputStream in = new BufferedInputStream(new FileInputStream(file));
byte[] buf = new byte[(int) file.length()];
int numRead = in.read(buf);
final Bitmap bitmap = BitmapFactory.decodeByteArray(buf, 0, numRead); <--- crash
How to avoid it?
E/dalvikvm-heap: Out of memory on a 31961104-byte allocation.
Am I understand good that 31MB is the limit to use memory? Using LRUCache
to store images. I set 60MB to store data. Is it too much?
public static int cacheSize = 60 * 1024 * 1024; // 4MiB
public static LruCache<String, Bitmap> images = new LruCache<String, Bitmap>(cacheSize) {
protected int sizeOf(String key, Bitmap value) {
return value.getByteCount();
}
};
In my case an image is around 3MB, and at least 18 image I need to store in cache. Is it so big demand from a phone to store 60MB?
I have a try catch around code, why app terminates?