is there a way to use HttpUtil synchronous ? In my app I parse a downloaded XML file:
B4X:
Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)
If parser.Parents.IndexOf("channel") > -1 Then
If Name = "name" Then
Title = Text.ToString
titles.add(Title)
Log(Title)
Else If Name = "address" Then
Link = Text.ToString
links.Add(Link)
Log(Link)
Else If Name = "type" Then
ctype = Text.ToString
ctypes.Add(ctype)
Log(ctype)
Else If Name = "iconUrl" Then
icon = Text.ToString ' not used
If icon="" Then
icon = "http://192.168.252.255/dummy.png"
End If
Log(icon)
icons.Add(icon)
icon=""
End If
End If
end sub
B4X:
Sub ImageUrlDone (Url As String)
If HttpUtils.IsSuccess(Url) Then
bitmaps.Add(HttpUtils.GetBitmap(Url))
Log("ImageUrlDone" & Url)
HttpUtils.SuccessfulUrls.Remove(Url)
End If
End Sub
Sub ImagesJobDone
For i = 0 To links.Size-1' HttpUtils.SuccessfulUrls.Size - 1
lv.AddTwoLinesAndBitmap(titles.Get(i), links.Get(i),bitmaps.Get(i))
Log(titles.Get(i) & links.Get(i)& bitmaps.Get(i))
Next
End Sub
after parsing the XML I need to download the ICONS list and put the PNG to the associated name etc. - but that failed obviously due to the async
Sub HandleMainPage
If HttpUtils.IsSuccess(ServerURL) = False Then
ToastMessageShow("Error loading page.", True)
Return
End If
in = HttpUtils.GetInputStream(ServerURL)
parser.Parse(in, "Parser")
HttpUtils.CallbackUrlDoneSub = "ImageUrlDone"
HttpUtils.DownloadList("ImagesURL", icons)
End Sub
it was clearly misunderstood from my side, my assumption that the download.list takes card of the right ordering is/was wrong :sign0148:
I solved it this way, not using ImageUrlDone at all :
B4X:
Sub ImagesURLJobDone
For i = 0 To HttpUtils.Tasks.Size - 1
Link = HttpUtils.Tasks.Get(i)
bitmaps.Add(HttpUtils.GetBitmap(Link))
lv.AddTwoLinesAndBitmap(titles.Get(i), links.Get(i),bitmaps.Get(i))
'Log(Link & ": success=" & HttpUtils.IsSuccess(Link))
Next
End Sub