0
votes

I have an app in production and am getting a lot of crashes on Galaxy devices.

Stacktrace:

java.lang.OutOfMemoryError at android.graphics.Bitmap.nativeCreate(Native Method) at android.graphics.Bitmap.createBitmap(Bitmap.java:669) at android.graphics.Bitmap.createBitmap(Bitmap.java:604) at android.graphics.Bitmap.createBitmap(Bitmap.java:530) at com.edmodo.cropper.CropImageView.getCroppedImage(CropImageView.java:357) at com.myapp.app.MyPhotoActivity$3.onClick(MyPhotoActivity.java:308) at android.view.View.performClick(View.java:4191) at android.view.View$PerformClick.run(View.java:17229) at android.os.Handler.handleCallback(Handler.java:615) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4960) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805) at dalvik.system.NativeStart.main(Native Method)

Types of devices:

Galaxy S2 (GT-I9100T) Galaxy S2 (SGH-T989) Galaxy Note II (t03g)
Galaxy Note2 (t0ltetmo) Galaxy Note2 (t0ltespr) Galaxy S3 (d2vmu)
Electrify M (solstice) Galaxy S5 (kltespr) Galaxy Exhibit (codinaMetroPCS) Galaxy S3 (d2tmo) Galaxy S3 (d2ltetmo) Galaxy S2 Epic (SPH-D710) Galaxy Win (delos3geur)

CropImageView

 // Crop the subset from the original Bitmap. (line 357 below)
        final Bitmap croppedBitmap = Bitmap.createBitmap(mBitmap,
                                                         (int) actualCropX,
                                                         (int) actualCropY,
                                                         (int) actualCropWidth,
                                                         (int) actualCropHeight);

        return croppedBitmap;
    }

MyPhotoActivity

usePhotoButton.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
// line 308 below
                    finalResizedBitmap = getResizedBitmap(mImageView.getCroppedImage(), PHOTO_RESIZE_VALUE, PHOTO_RESIZE_VALUE);
                    topCropView.setVisibility(View.GONE);
                    topFinalView.setVisibility(View.VISIBLE);
                    mFinalImageView.setImageBitmap(finalResizedBitmap);
                    usePhotoButton.setVisibility(View.GONE);
                    uploadPhotoButton.setEnabled(true);
                    uploadPhotoButton.setVisibility(View.VISIBLE);
                }
            });

The problem is I don't have any of these devices to test with - any ideas??

1

1 Answers

0
votes

The memory heap allocated to your application varies on the device, which is why you see variability based on the device. You may have as little as 16MB of RAM to work with on some devices. You can google to find the heap size on your devices in question.

http://developer.android.com/training/articles/memory.html

Prior to Android 3.0, bitmap allocation was done in the "native" heap, so you'll see some variability there as well. For devices using the native heap for bitmap allocation, I always found it true that the native heap was equal in size to the VM heap.

https://developer.android.com/training/displaying-bitmaps/manage-memory.html

You'll want to use BitmapOptions and proper scaling to lower your memory usage.

http://developer.android.com/training/displaying-bitmaps/load-bitmap.html

The examples in that article are very good, so I won't repeat an example of how to use them.

If you feel it necessary for your purposes, you can monitor your heap usage to avoid making allocations that will cause OOM.

How do I detect the heap size usage of an android application

Hope this helps!