Android Question CustomListView B4a Memory Fail Handler, DownloadImage And Picasso

rscheel

Well-Known Member
Licensed User
Longtime User
I tried with picasso and DownloadImage in both cases reaches a certain point and drops the application for lack of memory, it seems impossible now to make a list with images loaded in b4a, I know UltimateListView exists that possibly solve this problem, but my concern is That with the available libraries not of payments at the moment it is not possible to realize a list glan with images.



B4X:
Sub DownloadQuote
    Dim j As HttpJob
    j.Initialize("", Me) 'name is empty as it is no longer needed
    j.Download("https://api.themoviedb.org/3/movie/upcoming?api_key=Api_Key&language=es-CL&append_to_response=images&include_image_language=es&page="&pagina)
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        'The result is a json string. We parse it and log the fields.
        Dim jp As JSONParser
        Dim Map1 As Map
        Dim quotes As List
        jp.Initialize(j.GetString)
        Map1 = jp.NextObject
        quotes = Map1.Get("results")
        For Each quot As Map In quotes
            CustomList.Add(CreateListItem($"Item #${quot.Get("id")}"$, CustomList.AsView.Width, 70dip), 74dip, $"Item #${quot.Get("id")}"$)
            LabelVotos.Text = quot.Get("vote_average")
            LabelTitulo.Text = quot.Get("title")
            'DownloadImage("https://image.tmdb.org/t/p/w500/"&quot.Get("poster_path"), ImageView)
            GetPicasso.RunMethodJO("load", Array("https://image.tmdb.org/t/p/w500/"&quot.Get("poster_path"))).RunMethodJO("into", Array(ImageView))
        Next
    End If
    j.Release
    ProgressDialogHide
End Sub

B4X:
Refresh started
Refresh stopped
java.lang.OutOfMemoryError: Failed to allocate a 20 byte allocation with 0 free bytes and 3GB until OOM
    at com.squareup.picasso.Dispatcher.performBatchComplete(Dispatcher.java:380)
    at com.squareup.picasso.Dispatcher$DispatcherHandler.handleMessage(Dispatcher.java:516)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.os.HandlerThread.run(HandlerThread.java:61)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
There is no reason to use picasso to download images.

Bitmaps require a lot of memory. You should make sure to use LoadBitmapSample to avoid loading large images. Especially if you show thumbnails.

If you try to load many images then eventually you will run out of memory. The only way to solve it is to remove bitmaps that are not visible on the screen and reload them before they become visible. ULV already implements such a solution. If you don't want to pay for ULV then you will need to implement such a solution yourself.
In most cases it shouldn't be too difficult.
 
Reactions: eps
Upvote 0

rscheel

Well-Known Member
Licensed User
Longtime User
But to load the images with LoadBitmapSample, I need to have the images locally, it turns out that I'm using https://www.themoviedb.org/documentation/api, which gives me a json with the information to load in the list.

B4X:
{
    "results": [
        {
            "vote_count": 648,
            "id": 374720,
            "video": false,
            "vote_average": 7.5,
            "title": "Dunkerque",
            "popularity": 108.543773,
            "poster_path": "/iqkJigezfIzIx5duhN01jK8K5ga.jpg",
            "original_language": "en",
            "original_title": "Dunkirk",
            "genre_ids": [
                28,
                18,
                36,
                53,
                10752
            ],
            "backdrop_path": "/fudEG1VUWuOqleXv6NwCExK0VLy.jpg",
            "adult": false,
            "overview": "II Guerra Mundial. Cientos de miles de británicos y tropas aliadas están rodeados por las fuerzas enemigas. Atrapados en la playa con el mar a sus espaldas se enfrentan a una situación imposible mientras el enemigo se acerca. La película relata la Operación Dinamo, también conocida como el milagro de Dunkerque. Se trató de una operación de evacuación de las tropas aliadas en territorio francés, que tuvo lugar a finales de mayo de 1940. La operación permitió el rescate de más de 200.000 soldados británicos y más de 100.000 franceses y belgas.",
            "release_date": "2017-07-19"
        }
]
}
 
Upvote 0

rscheel

Well-Known Member
Licensed User
Longtime User
It would be nice if I could achieve this same with b4a without having to give so many laps to be able to do it, but it is what there is nothing else, I will continue to try, whenever there is need we must find the solution.

 
Upvote 0

rscheel

Well-Known Member
Licensed User
Longtime User
You can write a wrapper for this library if you want.
Or hire someone which does it for you. BUT paying someone to do the wrap will be more expensive than buying ULV.

It is that it turns out that what I want to do is an application not to sell which does not require to pay to be able to do it, if I can not solve it with b4a, I will do it with android studio, which means that I do not have to generate expenses to build the application.
 
Upvote 0

rscheel

Well-Known Member
Licensed User
Longtime User
ULV is 25USD....

You can try this https://www.b4x.com/android/forum/threads/java-method-recycle-not-found.17950/ for those Bitmaps which aren't visible.

They are 25 euros, not dollars, in Chilean pesos 25 euros or more it reaches me to travel half a month to my work.

I tried the recommendation of @Erel and works well, is not slow application or fall, at least I can reach the top of the list of new releases films, I would have to continue testing with more extensive lists.

Same along with it I will try to wrap UltimateRecyclerView, I think it would be very useful not only for me, for the whole community.
 
Reactions: eps
Upvote 0

eps

Expert
Licensed User
Longtime User
You're right - sorry! It is 25EUR not 25USD - although I thought they were about parity anyway.

Great to hear that you will try and wrap the RecyclerView - ask the forum if you need help
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Maybe UltimateListview does use a Recyclerview. If yes, then ULV is the solution. I have in mind i´ve read this somewhere....

There does not exists any Recyclerview Library as yet as far as i know of.

See also this.
No, it does not use a RecyclerView (such a view did not exist when ULV was created) but the concept behind is the same.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…