Uploading a file using this method:
try { String fileName = url.substring(url.lastIndexOf('/') + 1, url.length()); Log.w("isInCache", manager.hasImageInCache(fileName) + " " + fileName + " " + path + File.separator + fileName); if (!manager.hasImageInCache(fileName)) { URL urlConnect = new URL(url); ReadableByteChannel byteChannel = Channels.newChannel(urlConnect.openStream()); FileOutputStream outputStream = new FileOutputStream(path + File.separator + fileName); outputStream.getChannel().transferFrom(byteChannel, 0, Integer.MAX_VALUE); outputStream.close(); byteChannel.close(); return manager.putImage(fileName, BitmapFactory.decodeFile(path + File.separator + fileName)); } else { return manager.getImage(fileName); } } catch (IOException e) { Log.w("Download Exception: ", e.getMessage()); return null; } } Gives an error: E/AndroidRuntime: FATAL EXCEPTION: Thread-408 Process: *package*, PID: 7527 java.lang.OutOfMemoryError: Failed to allocate a 2147483659 byte allocation with 4194304 free bytes and 290MB until OOM at java.nio.ByteBuffer.allocate(ByteBuffer.java:56) at java.nio.FileChannelImpl.transferFrom(FileChannelImpl.java:397) at *package*.Util.HttpGetUtility.downloadFile(HttpGetUtility.java:87) at *package*.NewsActivity$1.run(NewsActivity.java:100) at java.lang.Thread.run(Thread.java:818)
I run the method in a separate thread, trying to load an image with a weight of ~ 870 KB.