Android Question Loading a lot of bitmaps

Slacker

Active Member
Licensed User
Longtime User
Hello Folks,
I have read other topics about Bitmaps memory issues; i need to load a photogallery with a lot of images and although i could load them as a sample, user could have around 100-200 images in his gallery which pictures are added/loaded moving scrolling down (page scrolling). I have seen memory grows rapidly as i load images in the inner list; the weight of each bitmaps is not so high but when their number become higher in the list, outofmemory exception is raised. Memory process could reach about 27-30 Mb (i have an old Smart Phone).

What is the best practice to follow in this case ? Any suggestions ?

Thanks in advance!
 

DonManfred

Expert
Licensed User
Longtime User
Just show only 10 images or something like that. and use a "next 10" button or something similar....
Android is NOT designed to load such a bunch of omages at once.
You can try to search for "Bitmapscaled" or somethink like that here in forum... Maybe this needs much less memory
 
Upvote 0

Slacker

Active Member
Licensed User
Longtime User
Thanks Don, but loading the next 10 images, i should have discard the previous ones i suppose...
 
Upvote 0

Slacker

Active Member
Licensed User
Longtime User
Yes, i suppose it was so. Mine is a community and there are often scenarios where i need to load "lists" of items; i did getting new items/results to add to the listview when scrolling position is at bottom (like Facebook); my purpose should be to get progressive growing of the list exactly as Facebook, but i think this is impracticable as the list could grow with hundred of result and going to outofmemory. I think i should create some strategy to discard previous results but make them available when the user scroll back up... i think someone here, faced similar problem....
 
Upvote 0

socialnetis

Active Member
Licensed User
Longtime User
In my opinion the trick is to use a real listview. Listview will manage all the recycling process and will help you to avoid the out of memory errors.
The fast and short theory behind listview is this:
- If there are X visible items in the listview, then there are only X (or X+1) items in memory (the listview can contain thousand of items, but there will only be an X number of visible items, and X being a small number)
- Lets say you have 10 visible items, and hundred of items in the listview. If the visible items are 1 to 10, and then you scroll a little bit to see items from 2 to 11, then the item number 1 will no longer be visible, then the listview will recycle the content of that items to be used as the number 11. So you can scroll as long as you want, and there will always be just 10 items in memory.

There are several option that you can find in the forum for listviews.
- The native one, which I think will not suit your needs, because you need some sort of custom rows (maybe 3 or 4 imageView in each row?)
- Create your own listview, this is a long path, you will need to know Java and understand all the logic behind the listviews.
- UltimateListView, the magic one, this will let you create the layout of a row using the B4A designer, but is chargeable.
 
Upvote 0

Slacker

Active Member
Licensed User
Longtime User
Socialnetis, thank you. I'm using CustomListView that Erel created; this component does not support this smart logic as the standard ListView i suppose....
 
Upvote 0

socialnetis

Active Member
Licensed User
Longtime User
CustomListview have all the elements in memory all the time, so you will hit an out of memory error very fast if you have lots of bitmaps
 
Upvote 0

Slacker

Active Member
Licensed User
Longtime User
Yes, i guessed it about. I suppose that standard listview implementation, save to disk/physical memory the non-visible items... is it so ? If so, is there view i can use which combine customlistview features with the optimized standard listview logic ?
 
Upvote 0
Top