Hi guys!
I already read this: https://www.b4x.com/android/forum/threads/b4x-okhttputils2-with-wait-for.79345/ where there is a snippet to "How to download a list of resources, one by one".
My question is: how to wait for completing all downloads and then do something?
Something like the project attached but I get this error:
So, the problem seems being in:
May someone help me to understand and get the wished result?
Thanks in advance!
Edit: the strange behavior is that if I put a breakpoint and go on step by step (i.e. F8 key), the error is not casted, but, however, I cannot see the logs of RangeDownload Sub and seems looping never reaching ExtractingAllZipFiles Sub.
I already read this: https://www.b4x.com/android/forum/threads/b4x-okhttputils2-with-wait-for.79345/ where there is a snippet to "How to download a list of resources, one by one".
My question is: how to wait for completing all downloads and then do something?
Something like the project attached but I get this error:
B4X:
Waiting for debugger to connect...
Program started.
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
Start downloading
Error occurred on line: 56 (cDownloadAndExtract)
java.lang.ClassCastException: class anywheresoftware.b4a.keywords.Common$ResumableSubWrapper cannot be cast to class anywheresoftware.b4a.BA$ResumableSub (anywheresoftware.b4a.keywords.Common$ResumableSubWrapper and anywheresoftware.b4a.BA$ResumableSub are in unnamed module of loader 'app')
at b4j.example.cdownloadandextract$ResumableSub_DownloadingAllFiles.resume(cdownloadandextract.java:384)
at b4j.example.cdownloadandextract._downloadingallfiles(cdownloadandextract.java:278)
at b4j.example.cdownloadandextract$ResumableSub_DownloadAndExtract.resume(cdownloadandextract.java:148)
at b4j.example.cdownloadandextract._downloadandextract(cdownloadandextract.java:109)
at b4j.example.b4xmainpage._button1_click(b4xmainpage.java:70)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.BA$1.run(BA.java:236)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
at java.base/java.lang.Thread.run(Thread.java:1589)
So, the problem seems being in:
B4X:
Private Sub DownloadingAllFiles(mylstURL As List) As ResumableSub
Dim mylstTasks As List
mylstTasks.Initialize
For i = 0 To mylstURL.Size - 1
Dim rs As ResumableSub = DownloadingEachFile(mylstURL.Get(i), i)
mylstTasks.Add(rs)
Next
Dim myynAllSuccess As Boolean = True
For Each rs As ResumableSub In mylstTasks
Wait For (rs) Complete (success As Boolean)
If Not(success) Then myynAllSuccess = False
Next
Return myynAllSuccess
End Sub
May someone help me to understand and get the wished result?
Thanks in advance!
Edit: the strange behavior is that if I put a breakpoint and go on step by step (i.e. F8 key), the error is not casted, but, however, I cannot see the logs of RangeDownload Sub and seems looping never reaching ExtractingAllZipFiles Sub.

Attachments
Last edited: