Android App crashing on Samsung Galaxy S3 (out of memory error)

前端 未结 4 2022
借酒劲吻你
借酒劲吻你 2021-02-05 13:02

I have an Android app that takes some pictures, re-sizes them and sends them over to the back-end server. This app works perfectly fine on all other phones (Gingerbread and Ice

相关标签:
4条回答
  • 2021-02-05 13:39

    umm... I know it's an old question now, but here's what I think.

    Galaxy S3 uses xhdpi density, therefore allocates bigger heap size on launching, (as far as I know, 32mb)

    but if you don't have any xhdpi resources in your res directory, then it will call any default images in drawable or from hdpi which is the closest to xhdpi density.

    Then it will expand the image to fit it's neeeds, and at this phases expanding the image will take up much memory, (might) resulting in out of memory issues.

    You can either solve this problem by enabling Screen Compatibility Mode or you can just create (if not there by default) drawable-xhdpi, providing Appropriate Resources for xhdpi devices such as Galaxy S3.

    0 讨论(0)
  • 2021-02-05 13:40
    I overwrote the onDestroy method and added the following line: layout.setBackgroundDrawable(null);. Please let me know if this worked or didn't work for you. 
    

    – user881148

    Cool, it worked for me... with a little added for background pics on a layout. Instead of using BitmapDrawables or Bitmap I use Drawables after convert from bitmap.

    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.outerspace);
    Drawable bitDraw = new BitmapDrawable(getResources(), bitmap);
    
    main.setBackgroundDrawable(bitDraw);
    

    My issue was that is was working on all devices expect for the S3 (which was annoying). But the app is up and running now! Thanx...user881148

    0 讨论(0)
  • 2021-02-05 13:42

    Wow. We have struggled with this Out of Memory issue on the S3 for weeks now. Finally, applied one of the techniques in this thread.

    In our app, we had drawable-hdpi have all the images for the app. On most phones, we had no issue . On the S3, the app would take 2x as much memory and then run into out of memory issue.

    I just created drawable-xhdpi folder with the same contents as drawable-hdpi folder and ran it on S3. Immediately noticed the memory footprint was 1/2 and no out of memory issues.

    This was a frustrating experience. Hopefully other people know to look for this thread and save hours of degugging.

    thanks

    0 讨论(0)
  • 2021-02-05 13:59

    I sort of solved the issue myself. The app running out of memory didn't have to do anything with the above code. I added the MAT and I saw that the bitmap objects were being kept alive from previous views. So I removed the graphics from the view and it solved the memory issue.

    0 讨论(0)
提交回复
热议问题