Android Question I want to run two services in a same loop with same URL, but different parameters.

Rajesh Gupta

Member
Licensed User
Hii,

I am using Http Request and Response, but for some reasons the job done for second service is never fired or it is fired anytime, means not in a sequence.

Anybody Please Help !!
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
can u provide an example code of what u are doing?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I Read it before also, but here in every examples the URL are different, but my URL is same, only the parameter differs.
What prevents you to create a job inside your loop with the same url but with different parameters and then "wait for" the answer of this call?

B4X:
    For i = 0 To 100
        Dim j As HttpJob
        j.Initialize("", Me)
        j.Download2("https://www.google.com", Array As String("key1", i))
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            Log(j.GetString)
        End If
        j.Release
    Next

You just need to understand how the wait for resp. resumeable subs are working.
 
Last edited:
Upvote 0

Rajesh Gupta

Member
Licensed User
can u provide an example code of what u are doing?

B4X:
For i = 0 To tblMasters.RowCount - 1
    tblMasters.Position = i
    ddlaccname.Text = tblMasters.GetString("MName")
 
    Dim job4 As HttpJob
    job4.Initialize("job4",Me)
    job4.Download("http://" & GlobalConst.IPAddress & ":" & GlobalConst.PortNo)
    job4.GetRequest.SetHeader("SC",GlobalConst.SC_GET_ACC_LEDGER_JSON)
    job4.GetRequest.SetHeader("Username",GlobalConst.BUSYId)
    job4.GetRequest.SetHeader("Pwd",GlobalConst.BUSYPwd)
    job4.GetRequest.SetHeader("MasterName", ddlaccname.Text)
    job4.GetRequest.SetHeader("StartDate", txtFrom.Text)
    job4.GetRequest.SetHeader("EndDate", txtTo.Text)
    job4.GetRequest.Timeout = 120000    'In Milliseconds i.e 2 minutes
    Wait For (job4) JobDone(job As HttpJob) '-------------------
 
    If job.Success Then
        pbImportTran.Visible=True
        If responseStr <>"F" And responseStr<>"" Then
            PartyJSON= responseStr.Trim
            OpBal= HttpUtils2Service.Response1.GetHeaders.Get("opbal")
            OpBal= OpBal.Replace("[","").Replace("]","")
         
            Dim parser As JSONParser
            parser.Initialize(JSONforParty)
            Dim root As Map = parser.NextObject
            Dim JSON As List = root.Get("JSON")
                         
            For Each colJSON As Map In JSON
                     
            vchtype= colJSON.Get("C2")
            vchcode= colJSON.Get("VchCode")

            If vchcode <> 0 Then
                If vchtype = "Sale" Or vchtype="Purc" Or vchtype = "SlRt" Or vchtype = "PrRt" Or vchtype = "MtIs" Or vchtype = "MtRc" Or vchtype = "Prod" Or vchtype = "StTf" Or vchtype = "SlOd" Or vchtype = "PuOd" Or vchtype = "UnAs" Or vchtype = "SJrl" Or vchtype = "SlQt" Or vchtype = "PrQt" Or vchtype = "PrIn" Then
                 
                    job8.Initialize("job8",Me)
                    job8.Download("http://" & GlobalConst.IPAddress & ":" & GlobalConst.PortNo)
                    job8.GetRequest.SetHeader("SC",203)
                    job8.GetRequest.SetHeader("Username",GlobalConst.BUSYId)
                    job8.GetRequest.SetHeader("Pwd",GlobalConst.BUSYPwd)
                    job8.GetRequest.SetHeader("VchCode", vchcode.Trim)
                                         
                    Wait For (job8) JobDone(Job As HttpJob) '-------------------
                    If Job.Success Then
                        pbImportTran.Visible=True
                        JobDone(job8)
                    End If
                Else
                             
                    job7.Initialize("job7",Me)
                    job7.Download("http://" & GlobalConst.IPAddress & ":" & GlobalConst.PortNo)
                    job7.GetRequest.SetHeader("SC",203)
                    job7.GetRequest.SetHeader("Username",GlobalConst.BUSYId)
                    job7.GetRequest.SetHeader("Pwd",GlobalConst.BUSYPwd)
                    job7.GetRequest.SetHeader("VchCode", vchcode.Trim)
                                             
                    Wait For (job7) JobDone(Job As HttpJob) '-------------------
                    If Job.Success Then
                        pbImportTran.Visible=True
                        JobDone(job7)
                    End If
                End If
            Else
                ToastMessageShow("Voucher Not Found", False)
            End If
            Next
        End If
    End If
Next


This is my code, when I am running the code then job7 and job8 doesnt works properly , it goes to wait for (job7) line and then return back to the loop.
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
job7.Initialize("job7",Me)
job7.Download(
"http://" & GlobalConst.IPAddress & ":" & GlobalConst.PortNo)
job7.GetRequest.SetHeader(
"SC",203)
job7.GetRequest.SetHeader(
"Username",GlobalConst.BUSYId)
job7.GetRequest.SetHeader(
"Pwd",GlobalConst.BUSYPwd)
job7.GetRequest.SetHeader(
"VchCode", vchcode.Trim)

Wait For (job8) JobDone(Job As HttpJob) '------
this is wrong. you are seting up job7 but wait for job8
Additionally you are NOT releasing any of your Jobs after the wait for. this is a mistake.
 
Upvote 0
Top