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.

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)
        Dim j As HttpJob
        j.Initialize("", Me)
        Log("Downloading: " & si.Images.Get(Index))
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            If Globals.ImageToDisk = True Then
            End If
            x = j.GetBitmap
            x = x.Resize(imgSlider.WindowBase.Width, imgSlider.WindowBase.Height, True)
            x = xui.LoadBitmapResize(File.DirAssets, "500px-No_image_available.svg.png", _
            imgSlider.WindowBase.Width, imgSlider.WindowBase.Height, True)
        End If
    End If
'    si.Slider.label1.Top = 90%y
'    si.Slider.label2.Top = 90%y
    Return FillImageToView(x,imgSlider)
End Sub



Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
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, 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.
Upvote 0

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.
Upvote 0