You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I'm working on a simple app that communicates (sends POST requests) to a remote server in order to apply complex image effects. At the moment, APIs require an image to be base64 encoded and sent as a part of a JSON payload.
Everything works perfectly in emulator but on a real device - I get OutOfMemoryError. The code is pretty simple and seems to consume around 20mb (I did a few tests using the same emulator).
File image = new File("/mnt/sdcard/DCIM/" + info.getFolder() + "/" + info.getFilename());
FileInputStream inputStream = new FileInputStream(image);
int size = inputStream.available();
byte[] buffer = new byte[size]; // 4MB
inputStream.read(buffer);
inputStream.close();
String base64Data = Base64.encodeToString(buffer, 0, buffer.length, Base64.DEFAULT); // 15MB
Stack trace from a device (Sony A6000) :
[ERROR] java.lang.RuntimeException: An error occured while executing doInBackground()
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:200)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
at java.lang.Thread.run(Thread.java:1019)
Caused by: java.lang.OutOfMemoryError
at android.util.Base64.encode(Base64.java:534)
at android.util.Base64.encodeToString(Base64.java:477)
at com.github.ma1co.pmcademo.app.ImageAsyncTask.doInBackground(ImageAsyncTask.java:42)
at com.github.ma1co.pmcademo.app.ImageAsyncTask.doInBackground(ImageAsyncTask.java:13)
at android.os.AsyncTask$2.call(AsyncTask.java:185)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
... 4 more
The system itself seems to have around 82Mb of RAM available, so what could cause the issue? I'm pretty new to a mobile developent, but does Android has a limitation per activity\background task?
I'm using Android 4.04 for the emulator.
The text was updated successfully, but these errors were encountered:
Hi,
I'm working on a simple app that communicates (sends POST requests) to a remote server in order to apply complex image effects. At the moment, APIs require an image to be base64 encoded and sent as a part of a JSON payload.
Everything works perfectly in emulator but on a real device - I get
OutOfMemoryError
. The code is pretty simple and seems to consume around 20mb (I did a few tests using the same emulator).Stack trace from a device (Sony A6000) :
The system itself seems to have around 82Mb of RAM available, so what could cause the issue? I'm pretty new to a mobile developent, but does Android has a limitation per activity\background task?
I'm using Android 4.04 for the emulator.
The text was updated successfully, but these errors were encountered: