Android Question Best way to download files

Avansys

Member
Licensed User
Longtime User
Hello folks,

I've implemented Erel's code http://www.b4x.com/android/forum/threads/download-huge-files-with-httputils2.30220/ in my program to download different kind of files.

However, the program downloads files one by one to ensure that all files have been downloaded but I think it slows the proccess.

Is there an update to improve performace?

Thank's in advance.

The algorythm is the following:
1) Save DownloadData objects to a List
2) Verify if list contains objects. If true then download first file and every _Complete event program verifies if more objects exists in list. If true then download next file and so on,
 

Avansys

Member
Licensed User
Longtime User
Do you have an example?

How can I ensure that all files are downloaded and ready to use?
 
Upvote 0

Avansys

Member
Licensed User
Longtime User
B4X:
Dim dialogoAudio As DownloadData
            dialogoAudio.fileName = tempDialogoObject.identificador & ".mp3"
            dialogoAudio.url = Comun.ObtenerUrlParaAudios & tempDialogoObject.Audio
            dialogoAudio.EventName = "dialogoAudio"
            dialogoAudio.Target = Me
            mediaParaDescargarList.Add(dialogoAudio)
            'CallSubDelayed2(DownloadService, "StartDownload", dialogoAudio)

Then...

B4X:
Sub dialogoAudio_Complete(job As HttpJob)
    Dim jobTagTemp As JobTag
    jobTagTemp.Initialize
    jobTagTemp = job.Tag
    Dim out As OutputStream
    Dim banderaObject As banderaObjeto
    banderaObject = BaseDatos.ObtenerBandera("almacenamiento")
    If banderaObject.valor = 1 Then
        out = File.OpenOutput(File.DirRootExternal & "/mybackpackguide/audios/dialogos", jobTagTemp.Data.fileName, False)
    Else
        out = File.OpenOutput(File.DirDefaultExternal & "/audios/dialogos", jobTagTemp.Data.fileName, False)
    End If
    File.Copy2(job.GetInputStream, out)
    job.Release
   
    ' Descargamos los archivos media
        contadorDeMediaParaDescargar = contadorDeMediaParaDescargar + 1
       
        If contadorDeMediaParaDescargar <= mediaParaDescargarList.Size Then
            ' Actualzamos el dialogo de progreso
                ProgressDialogHide
                ProgressDialogShow2("FILE " & contadorDeMediaParaDescargar & " of " & mediaParaDescargarList.Size, False)
               
            ' Obtenemos el objeto
                Dim tempDownloadData As DownloadData
                tempDownloadData = mediaParaDescargarList.Get(contadorDeMediaParaDescargar - 1)
               
            ' Descagamos
                CallSubDelayed2(DownloadService, "StartDownload", tempDownloadData)
        Else
            ' Actualizamos la bandera
                BaseDatos.ActualizarBandera("sync", Comun.ObtenerFechaActual, 1)
               
            ' Mostramos mensaje de confirmación
                StartActivity(Main)
                Msgbox("Updated finished.", "")
        End If
End Sub

Sub dialogoAudio_Progress(Progress As Long, Total As Long)
   
End Sub

That's what I have.. Is that correct? Just include a counter?
 
Upvote 0
Top