Android Question Issues with image slider and event imgSlider_GetImage

Christian García S.

Active Member
Licensed User
Hello, maybe you can help me with this behavior.

I have in main screen a CustomListView with multiple ImageSliders with a lot of images, and I download images with ImageSlider1_GetImage.

In some devices take a long time to get images, and the user navigate in other menus, and when the image is complete downloaded the main screen appear againg and new activity user open was closed, there are some way to avoid this behavior maybe blocking with progress dialog, but I dont know when the all images are downloaded.

Sometimes happend other times not.

Thanks for your help.

B4X:
Sub imgSlider_GetImage (Index As Int) As ResumableSub
    Dim slider As ImageSlider = Sender
    Dim IndexInList As Int = slider.Tag
    Dim si As SliderAndImages = clvcards.GetValue(IndexInList)
    Dim image_link As String
    
'    Log("imgSlider_GetImage " & Index & " " & IndexInList)


    ProgressDialogShow2("Procesando imágenes...",False)

    image_link = GetFileName(si.Images.Get(Index))
    
    Dim x As B4XBitmap
    
    If File.Exists(File.DirInternal,image_link) Then
        x = xui.LoadBitmapResize(File.DirInternal,image_link,imgSlider.WindowBase.Width, imgSlider.WindowBase.Height, True)
    Else
        Dim j As HttpJob
        j.Initialize("", Me)
    
        j.Download(si.Images.Get(Index))
        Log("Downloading: " & si.Images.Get(Index))
        Wait For (j) JobDone(j As HttpJob)
        
        If j.Success Then
            If Globals.ImageToDisk = True Then
                SaveImagetoDisk(j,image_link)
            End If
            x = j.GetBitmap
            x = x.Resize(imgSlider.WindowBase.Width, imgSlider.WindowBase.Height, True)
        Else
            x = xui.LoadBitmapResize(File.DirAssets, "500px-No_image_available.svg.png", _
            imgSlider.WindowBase.Width, imgSlider.WindowBase.Height, True)
        End If
        j.Release
    End If
    
    ProgressDialogHide
    
'    si.Slider.label1.Top = 90%y
'    si.Slider.label2.Top = 90%y
    
    Return FillImageToView(x,imgSlider)
    
End Sub
Thanks,

Christian
 

Andrew (Digitwell)

Active Member
Licensed User
Christian,
I believe the problem is that the Closed activity is being restarted to handle the JobDone when the Wait For completes.

A solution is to use the Imagedownloader, https://www.b4x.com/android/forum/t...-simple-way-to-download-images.30875/#content which handles the download in a service.

You can then call "ActvityIsPaused", which halts the downloading.

It will probably need a bit of tweaking as InageDownloader expects an ImageView to write to.
 

Christian García S.

Active Member
Licensed User
Hi Andrew thanks.

It is more difficult than expected, because the getimage event receives a bitmap and the imagedownlader jobdone puts the image directly on the object how do I make the service jobdone return an image to the event that started the download.
 
Top