using cardview on top of recycler view crashes system - android

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.

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

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.

Related

How to correctly manage TextViews and ImageViews so they don't use a lot of RAM?

I have an android app that consists mainly of TextViews and a few ImageViews, it also has some buttons all coded into the xml. I have 4 fragments and a MainActivity, each fragment is its own screen for use with a bottom navigation bar. The problem is: My app will take as much as 340mb of ram on my physical device, I could not find any resources that explain how to properly load images and text so that they don't take so much RAM. Can anyone share some resources on RAM management for android?
I can suggest you some tips to decrease your memory usage:
- Flatten your layout, less using nest layout
- Instead of using many TextViews for layout, use can use less TextView combine with Html.from(format your text like htlm>
- Scale your load image to a lower size
- Limit your memory leak, use this Leakcanary
- Dump your memory usage by using Dump Memory in Android Profiler of Android Studio, so that to find out variables that used most memory.
That all! I think these is enough for you to troubleshoot memory and increase your app's performance. Hope this help.
Android studio has a tool called Android Profiler which allows you to profile and monitor the memory usage of your app. You could make a judgement from there on what consumes most memory of your phone.
My guess is the images you load. You probably need to sample and resize the images when you load them. It is common to use library such as Glide to handle it for you.
Here is another article on Android, Manage your app's memory could give your some information on how to manage your app memory in general.

NativeScript Fresco still crashes app with out of memory

As I navigate through my NativeScript app, I keep running into out of memory crashes. I tried to resolve this by first upgrading {N} with #next for both tns-core-modules and tns-core-modules-widgets. I then installed nativescript-fresco and replaced all image tags with Fresco. It seems to of helped a bit but eventually if I navigate back and forth between a list view of images to another page, the app eventually crashes.
So I have a question regarding the usage of Fresco.
Let's say I have a bunch of images that is 1600 x 1200 and 1MB each.
And I use Fresco to display these images in a list view at thumbnail size like
100 x 100 square, does the app still load each of these images as a file size of 1MB each? Or does fresco create a thumbnail size and load a smaller file size version of the images?
I'm guessing that this maybe the reason why the app still crashes?

Memory issue with my Android app

Hi my Android application is working fine on my Lenovo a319 device , in this device it consuming 40 MB of RAM meanwhile on the Galaxy s5 Device , it consuming 300 Mb for the same build(apk). And I am getting lot of errors such as memory issue on Galaxy s5 device.
For Instance
Out of memory
exception and
android.view.InflateException: Binary XML file line
errors. I have found this Question where it is answered that high pixel resolution will cause memory exception , I am not able to get any clue from that answers provided in that Question , kindly provide the support on the same?
EDIT:
Thanks for the answers but they are inacurate i reuse recycle bitmaps and i make them null, even call system.gc(); and my memory is constant, i just do not understand that why it takes 300 MB of ram at sumasung galxy s5 and just 40 on my lenovo. My lenovo is hdpi s5 is xxhdpi if i am sure.
Looks like your app was built using layouts defined in xml files. These layouts uses images like images for background or source images for ImageButton or ImageView etc. All your drawables are usually stored in drawable-DENSITY folders. So you need to lower resolution of all of your drawables to save some RAM. Like if you have some drawable for ImageView lets call it new_image.jpg and its in drawable-hdpi and its resolution is 800x600 px try to resize it to 400x300 px (you could use a Farstone Image Viewer for this). Do that with every drawable in project and see what happens.
Also it could be that you are displaying images in ListViews using some ImageLoader like Glide (recommended) or UIL or Picasso or whatever use use. Such loaders are usually consuming a lot of RAM (which is configurable however) for caching needs and due to that at one point AOS fails to load, build and represent some your layout which uses images by itself.
Also I recommend you to lern how to display Bitmaps efficiently you MUST know such things.
This thing can be an easy fix for this
just add this line in your application tag in manifest file
android:largeHeap="true"
like this
<application
android:largeHeap="true"
android:allowBackup="true"
......
and if you want to more optimize your code then use Memory Analyser in eclipse
Apart from bitmaps and drawables the most common problem is leaking memory through the Activity context. Make sure that you are not passing around the activity to callback listeners.
A good tool to analyze memory is MAT(Memory Analyzer Tool). It helps you find out memory leaks in your app

Manage heap size

I am loading images from database in may android app using bitmap.Since my app contains lot of images I am getting out of memory error. I have also given the permission android:largeHeap="true" in manifest file. I have also used system.gc() but nothing solve my purpose.The heap size gets increased as my app proceeds. How can I manage my heap size? I have also scaled the image when I am using bitmap.
You are testing your app on emulator or device??? Try to test it on device. Another thing is use lazy loading & same time you can use clearing cache to decrease memory load.

Android memory management

I am working on an Android app, that has lots of images (a few hundred) to be displayed in a grid format. I am using a custom HorizontalListView and a couple of LazyLoading, Caching techniques to achieve the required UI.
What I have noticed (in DDMS) is, the app consumes a lot more memory on Android 3.2 compared to Android 2.3.3 I was expecting a small difference, however my app consumes about 35Mb on Android 3.2 and only 12Mb on 2.3.3. Any particular reason for such a huge difference?
Are you considering supporting multiple screens while loading images?
I think your problem is screen type and the size of image. If you focus on this area, you may get improved results.

Categories

Resources