I'm trying to create an Android ListView that will look like Instagram pictures feed or Facebook's. I'm getting Out Of Memory Exception on my Galaxy Nexus after loading some images (only a few). I scaled them, but still, the number of images isn't fixed and theoretically can be unlimited. On Facebook and Instagram they load lots of images and other data and it works well.
What do you think? Can i achieve those performances with native Android coding?
If i'll create a HTML5 feed (like Facebook and Instagram) will i avoid the memory problem?
It feels weird for me that I need to do so much work handling the memory of images coming from server. If it's the only solution, what is the way to go for managing hundreds of pictures in native ListView?
I will appreciate any opinion!
Thanks.
Don't load them all into memory at once, only load the images you need to display into Bitmap
objects; and make sure the images you load are only the size you need to display (don't fully load a 1900x1200 image to show a 300x200 thumbnail). Your application's heap size is ~30MB (device dependent, but that's a good rule of thumb), and a Bitmap
will take up Width*Height*4 bytes in memory once loaded.
One method is to cache the images onto disk as they are downloaded so they don't have to be in memory, and always check the cache for an image before downloading it. You can also use the cache to load up a handful of images into memory that need to be displayed in the list at that time.
You can also make use of the BitmapFactory.Options.inSampleSize
options to reduce the size of an image while it is loaded, rather than loading in the entire image and then creating a small copy, which wastes time and memory.
HTH
Take a look at : http://developer.android.com/training/displaying-bitmaps/index.html for help