Android Question B4Agalleryview 3.10 and OutOfMemoryError

kostefar

Active Member
Licensed User
Longtime User
Dear All,

I modified the example in https://www.b4x.com/android/forum/threads/library-b4agallery-v3-55.24963/#content a bit:

B4X:
    Gallery.Initialize("Gallery")
    Activity.AddView(Gallery, 0, 105dip, 100%x, 100%y)
   
    'Gallery.CreateCache = "Pippo.Pluto.Paperino"

    Gallery.TextSize = 16
    Gallery.TextColor = Colors.Yellow
    Gallery.ShowText = False
    Gallery.ItemWidth = 140
    Gallery.ItemHeight = 140
    Gallery.Spacing = 10
   
    '*************************************
   
    'Gallery.ScaleType = Gallery.ScaleType.Center_Crop
    Gallery.ScaleType = Gallery.ScaleType.Center_Crop
    Gallery.SetNoEffect = True
    Gallery.SetBorderColor=Colors.Yellow
    Gallery.SetCornerRadius = 0
    Gallery.SetBorderWidth = 0
    Gallery.SetOval = False
   
    '*************************************

    Gallery.ShowFromMediaStore

And it did what I wanted. Then I tried moving it to the code for the app I´m working on, but got:

B4X:
java.lang.OutOfMemoryError: OutOfMemoryError thrown while trying to throw OutOfMemoryError; no stack trace available
java.lang.OutOfMemoryError: Failed to allocate a 12 byte allocation with 3424 free bytes and 3KB until OOM

I tried copying my manifest over to the example app, in order to find out if something there could have any impact, but that one was still running fine.
Then I tried doing so that loading the gallery would be the very first thing happening in my own app, and nothing else would happen after that - just to see if something happening in the app would take up alot of space, but still the same.
Then I tried with
B4X:
SetApplicationAttribute(android:largeHeap, "true")
in the manifest, still no luck.
I then tried increasing the memory in the genymotion emulator from 2048 to 3172 - same result.
Then I found out that if removing gallery.showfrommediastore, things are working. Obviously this one is crucial, but maybe it gives a hint of what is going on? There are only some 15 pics in the mediastore of the device.
The reason that I´m not using the 3.55 version of the lib is that if I do so, some properties of the library from v3.10 are no longer recognized.

The app I´m working on is pretty large, and there´s a lot of things that I want to remove from it, but I doubt this would be of any help since the problem occurs even before the app has done anything else than just loaded.

Does anybody have any ideas about what´s going on here?

Thanks in advance!
 

kostefar

Active Member
Licensed User
Longtime User
(I'm just guessing here)
Maybe your pics are to big.
Try it with some realy small pics and see if it works.

Thanks, so I just tried this.. moved all photos, which were indeed large but worked fine with the example, to another folder. Put an image that´s only 300x300 pixels and 50 kb there. Same problem.
Only if the folder is empty I don´t get the outofmemory error...
 
Upvote 0

rboeck

Well-Known Member
Licensed User
Longtime User
Try the new beta 3.7 - there is a new feature exactly for this situation: LoadBitmapResize. Search in the forum, it could be the feature you need in this situation!
 
Upvote 0

kostefar

Active Member
Licensed User
Longtime User
Try the new beta 3.7 - there is a new feature exactly for this situation: LoadBitmapResize. Search in the forum, it could be the feature you need in this situation!

Thanks rboeck, but I cannot find this anywhere. Are you sure it´s not photopager, of which there´s a v 3.8?
 
Upvote 0

kostefar

Active Member
Licensed User
Longtime User
Upvote 0

kostefar

Active Member
Licensed User
Longtime User
Update: Decided to go with https://www.b4x.com/android/forum/threads/lib-class-customgallery.20082/ instead. No memory errors there!

And yet another update. Maybe I missed it, but the above does not have loadimageasync which makes it too slow for what I wanted to achieve.
Hence, I fiddled and fiddled with UltimateListView and came up with a lovely horizontal gallery scroll view, loading images at the speed of light! :)
Can´t emphasize enough how amazing ULV is, and really worth spending time to understand.
 
Last edited:
Upvote 0
Top