0

Why does using large images using cardview crash the android system? I used 1280 X 600 images for cardview, but launching the app after install crashes the system presents a out of memory error from the logcat.

I had atleast 400MB of RAM while launching the app(viewed using simple system monitor), but yet the app crashes. Is the cardview designed to work with only small images? What if we have to use larger images for larger dpi devices? The cardview was used with a recycler view and the OS which it was tested on was KitKat.

Kaushik Burkule
  • 816
  • 1
  • 12
  • 27
juztcode
  • 1,196
  • 2
  • 21
  • 46

2 Answers2

1

I was running into the same issue. Adding android:largeHeap="true" to tag in AndroidManifest.xml solved the issue for me on my physical Android but I'm a bit concerned that this might still be an issue for some devices with less memory?!?

You don't mention how you want to show the image is it card background or a imageview into a cardview. If you want to use ImageView into a CardView then you can use picasso or glide library to handle this issue.

Out of memory error is very common error when you are developing for a application that deals with multiple images sets or large bitmaps or some Animation stuff. In this case we have to be very careful and efficient while handling the images or object allocation and deallocation. OOM error comes when the allocation crosses the heap limit or your process demand a amount of memory that crosses the heap limit.

pavel
  • 1,603
  • 22
  • 19
  • I wanted to display a Captioned Image, yes, using the image view, and thanks for the picasso and glide tip, I'll try it – juztcode Oct 13 '19 at 07:15
1

You may have 400 MB RAM but all the RAM will not be directly provided to your application so application will crash...if you want to use different dpi images for different devices then you can add that to drawable, drawable-mdpi, drawable-xhdpi,drawable-xxhdpi etc. folder so that system can select them automatically....if you are loading from a url...then you can use third party libraries like Picasso, Glide etc to load the image efficiently

Also, in your question you are saying that you are adding card view in recycler view...which means more than one 1280x600 images will be loaded which will take a lot of memory and make your app to crash.

For your question "Is the cardview designed to work with only small images?" No, cardview is not related to your out of memory... its the image size and Memory provided for you...card view can work with any size of image.

Adding Adding android:largeHeap="true" to your menifest can help you to some extent

unownsp
  • 727
  • 5
  • 19
  • what if the large image used with the large dpi devices crashes them? – juztcode Oct 13 '19 at 07:17
  • for specific dpi devices they will be able to show images of large size to some extent...you just have to do some hit and trial and find the size of the image that will not crash it...and implement the images accordingly....i would recommend to test your application with different sizes and types of images so you will understand how it works....you will not require very large image to show the clear image....significantly small image will show all the required detail without user noticing the difference – unownsp Oct 13 '19 at 07:24