I am facing this error :
FATAL EXCEPTION: main Process: com.petyaar, PID: 18056 java.lang.OutOfMemoryError: Failed to allocate a 63701004 byte allocation with 16777024 free bytes and 40MB until OOM at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:639) at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:615) at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:391) at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:419) at com.petyaar.OwnerBio.OwnerBioUpdate.onCaptureImageResult(OwnerBioUpdate.java:611) at com.petyaar.OwnerBio.OwnerBioUpdate.onActivityResult(OwnerBioUpdate.java:643) at android.app.Activity.dispatchActivityResult(Activity.java:6508) at android.app.ActivityThread.deliverResults(ActivityThread.java:3702) at android.app.ActivityThread.handleSendResult(ActivityThread.java:3749) at android.app.ActivityThread.access$1400(ActivityThread.java:153) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1400) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5441) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
I don't know how to resolve this, also I have been monitoring my memory allocation in "Android Monitor" . The memory allocation keeps on increasing even when I am not interacting with the app . It goes to as high as 500MB+.
This is what I am doing with my image captured through camera .
private void onCaptureImageResult(Intent data) {
Bitmap thumbnail = null;
String[] projection = {MediaStore.Images.Media.DATA};
Cursor cursor = managedQuery(mCapturedImageURI, projection, null,
null, null);
int column_index_data = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
//THIS IS WHAT YOU WANT!
String capturedImageFilePath = cursor.getString(column_index_data);
filename = capturedImageFilePath.substring(capturedImageFilePath.lastIndexOf("/") + 1);
thumbnail = BitmapFactory.decodeFile(capturedImageFilePath);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
thumbnail.compress(Bitmap.CompressFormat.JPEG, 50, bytes);
thumbnail=Bitmap.createScaledBitmap(thumbnail, 200, 300, true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Log.i("final camera size", String.valueOf(thumbnail.getAllocationByteCount()));
}
File destination = new File(Environment.getExternalStorageDirectory(),
System.currentTimeMillis() + ".jpg");
byte[] byteArray = bytes.toByteArray();
encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
Log.e("base64string name", encoded);
Log.e("Image name", capturedImageFilePath);
FileOutputStream fo;
try {
destination.createNewFile();
fo = new FileOutputStream(destination);
fo.write(bytes.toByteArray());
fo.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
profile_image.setImageBitmap(thumbnail);
}
Please tell me how to resolve this issue.