Android Question problem with simple media manager

hi guys.
in b4xPages, images are loading by smm perfectly. problem is: loadings stops when I go to the next page before loading images successfully. background is white and all urls are ok. any advice
 
Upload an example or code that you are using.
B4X:
Private Sub clv_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
    For Each i As Int In PCLV.VisibleRangeChanged(FirstIndex, LastIndex)
        Dim item As CLVItem = clv.GetRawListItem(i)
        Dim pnl As B4XView = xui.CreatePanel("")
        item.Panel.AddView(pnl, 0, 0, item.Panel.Width, item.Panel.Height)
        Dim data As MyImageData = item.Value
        
        pnl.LoadLayout("item")
    
        For x = 0 To 2
           MediaManager.SetMedia(pnl.GetView(x).GetView(0), $"https://picsum.photos/id/${data.IndexOfFirstImage + x}/200/300.jpg"$)
        Next
    Next
    MediaManager.TrimMediaCache

End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
SMM avoids creating new views if it can reuse existing ones. When an image becomes invisible its containing view becomes eligible for reuse.

You need to do three things:
1. Better to create a single SMM object and reuse it. Make the on in B4XMainPage a Public variable and in the other pages:
B4X:
smm = B4XPages.MainPage.smm
2. Add this to B4XMainPage:
B4X:
Private Sub B4XPage_Appear
    clv_VisibleRangeChanged(clv.FirstVisibleIndex, clv.LastVisibleIndex)
End Sub
3. In the second page, change the "download" sub to B4XPage_Appear. And don't call it from the main page. It will be called automatically.
 
Upvote 0
SMM avoids creating new views if it can reuse existing ones. When an image becomes invisible its containing view becomes eligible for reuse.

You need to do three things:
1. Better to create a single SMM object and reuse it. Make the on in B4XMainPage a Public variable and in the other pages:
B4X:
smm = B4XPages.MainPage.smm
2. Add this to B4XMainPage:
B4X:
Private Sub B4XPage_Appear
    clv_VisibleRangeChanged(clv.FirstVisibleIndex, clv.LastVisibleIndex)
End Sub
3. In the second page, change the "download" sub to B4XPage_Appear. And don't call it from the main page. It will be called automatically.
thank you, dear Erel. It works great.šŸ‘:)
 
Upvote 0
Top