Android memory management - android

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.

Related

React Native / Android: Show high resolution image

I'm working on an app that shows the floor plan of a trade fair. This is a high resolution (3500x4600), but fairly low file size (400kb) PNG image. I have a little component that allows to pan / zoom it.
Now it all works just fine on iOS, but on Android I just cannot get it to work. If I just try to load it in the normal RN (0.56) Image component I get a blank screen. I'm testing on an HTC One M8, which is not exactly brand new, but also not super low end (2 GB Ram). Funnily enough, if I convert it to a 2,6 MB jpg with the same dimensions, it will show up, though the quality is so bad, you cannot read any of the labels.
There are some mostly older github issues on this (like here and here), but none of those solutions (android:largeHeap="true") work for me.
I tried using react-native-svg, but it has the same problem (I guess it eventually gets rasterized?).
I also tried using react-native-fast-image, which uses Glide under the hood instead of Facebook's Fresco, but (you guessed it), it also doesn't work. If I just load the image, it will get downsampled (worse than the jpg). I tried to get Glide to stop doing that (using override), but then I get a blank screen again.
I found this library, which I guess does exactly what I want, but I'd have to wrap it for RN use... which would be quite a bit of work.
Anyone have an idea?

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.

How big android applications like Amazon , Flipkart , Myntra has very less cache though they load a lot of images? Where do they store images?

I am developing an android application , How so ever it has memory issues for Kitkat devices. How do these firms do to optimize their memory usage?
They will only load a low resolution image as a preview that fits exactly the size of the element. This is also stated on the Android Developer Page. I would suggest you to follow this training and see if it helps you.
Given that you are working with limited memory, ideally you only want to load a lower resolution version in memory. The lower resolution version should match the size of the UI component that displays it. An image with a higher resolution does not provide any visible benefit, but still takes up precious memory and incurs additional performance overhead due to additional on the fly scaling.

How much memory should I be using for an image in Android Studio?

My application uses far too much memory, and uses a lot of images on one of the activities. I went to my main menu which only has 2 image buttons and a background image and removed all of the images from it to see what kind of memory it used... It still seems pretty high for nothing on the page.
http://imgur.com/6pfNlxf
Any idea what I'm doing wrong? Or are these normal numbers? In the activity that uses a lot of images, the allocated memory is much higher around 250MB, and crashes if I don't use my tiny scaled down images.

Android devices GL_MAX_TEXTURE_SIZE limitation, safe texture size

I am working with AndEngine and OpenGL ES 2.0. I keep reading about GL_MAX_TEXTURE_SIZE and how I should keep my texures under 1024x1024. I started wrong before and while using tilesets in TMX extension (doesn't really matter what it is, if you don't know AndEngine) I get to a tileset that makes a texture wider than 1024px. I am thinking of splitting the tileset into two, making them "safe". But I can't find any device released in last couple of years that has this limit set under 2048x2048. Is there any list or website I can use to filter devices by GL_MAX_TEXTURE_SIZE?
I read the following questions:
Minimum required Texture Size for compliance with OpenGL-ES 2.0 on Android?
Is there any Android device with screen size greater than GL_MAX_TEXTURE_SIZE?
And I used this site to search for devices. But I can't search by/filter by GL_MAX_TEXTURE_SIZE, which makes the search tedious. I am asking mostly because I started wrong, it's a hobby project and the amount of work might be too large compared to the number of possible devices that will be enabled (I expect 0).
1024x1024 is about the safest you can go on any device, especially on older ones. Newer devices shouldn't have any problem, although I've seen recent devices (I recall a Galaxy Nexus, the newest ICS update fixed that though) render white quads with texture sizes of size 2048x1024.
If you're targeting new devices and want to keep older ones compatible, it shouldn't hurt to split your tilesets. After all, you aren't likely to do too many context switches if you use two or three spritesheets for background, etc.
If you still have the individual image files, breaking them into small sized Atlases or custom sized atlases is easy if you use the TexturePacker2 tool from the LibGdx library.
I don't know the exact limitation of devices, but it's always better to take into consideration the lowest end of device you want to support and build upward from there. Using the LibGdx tool, you can easily change your mind later, so it's the most flexible solution.
Look at:
LibGdx TexturePacker

Categories

Resources