Android Question RDC many jobs on one activity - jobdone issue

ewwwa

New Member
Licensed User
Longtime User
Hello,
I would like to run several jobs usung one activity, but still have a problem with understanding jobdone.
It is raised when the main activity is finish. Then I would like to start another job but i dont think it is a good idea to make it from inside jobdone sub.
But anyway I dont know how to start next procedure automatically without any user action.

I would appreciate for a hint.
 

DonManfred

Expert
Licensed User
Longtime User
What exactly you want to do?
You have to do some jobs in order?

Call your first job. ex named "job1"... In job done you can start the next job (job2) after you handled the results from job1. After job2 finishes you then can start job3. and so on...

You just have to structure your code in an other way. that´s all.
 
Upvote 0

ewwwa

New Member
Licensed User
Longtime User
Thank you very much,
It was my idea but because im very beginner I was not sure about this solution. It seems a bit muddy.
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
Then I would like to start another job but i dont think it is a good idea to make it from inside jobdone sub.
As DonManfred has already stated, this is perfectly acceptable and the norm for downloading several items consecutively. Why do you feel that it is not a good idea?

Regards,
RandomCoder
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
because im very beginner

Ok, then i will show a small example


B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")
    lv.FastScrollEnabled = True
    lv.SingleLineLayout.ItemHeight = 30dip
  lv.SingleLineLayout.Label.TextSize = 12
  lv.SingleLineLayout.Label.TextColor = Colors.Green
  lv.SingleLineLayout.Label.Gravity = Gravity.CENTER
    lv.TwoLinesLayout.ItemHeight = 60dip
    lv.TwoLinesLayout.Label.TextSize = 10
    lv.TwoLinesLayout.Label.TextColor = Colors.Red
    lv.TwoLinesLayout.Label.Gravity = Gravity.CENTER
    lv.TwoLinesLayout.SecondLabel.TextSize =12
    lv.TwoLinesLayout.SecondLabel.TextColor = Colors.Red
    lv.TwoLinesLayout.SecondLabel.Typeface = Typeface.DEFAULT_BOLD
    joblist.Initialize
    jobresults.Initialize
    If FirstTime Then
  End If
    ' You can fill this list with the jobs you have to do...
    joblist.Add("dummy")
    joblist.Add("dfghdfgd")
    joblist.Add("dfgertzer")
    joblist.Add("rtertertet")
    joblist.Add("tewtwete")
    joblist.Add("init")
    joblist.Add("tabellen")
    joblist.Add("paarungen")
   
   
    If joblist.Size > 0 Then
        Label1.Text = "Executing Job "&joblist.Get(0)&"..."
        ExecuteRemoteQuery(joblist.Get(0),joblist.Get(0))
        ' the further logic goe on in sub FTP_DownloadCompleted
    End If
End Sub

Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub ExecuteRemoteQuery(Query As String, JobName As String)
    Dim job As HttpJob
    Dim dummy As String
    job.Initialize(JobName, Me)
    job.download2("http://vdfb.de/b4a/", Array As String( _
        "action", Query _
    ))
End Sub
Sub JobDone(Job As HttpJob)
    ProgressDialogHide
    ' Delete the topmost job in ftpjobs
    If joblist.Size > 0 Then
        joblist.RemoveAt(0)
    End If

    If Job.Success Then
        Dim res As String
        res = Job.GetString
        If Job.JobName = "tabellen" Then
            Log("JobName: "&Job.JobName&"/Response:" & res)
        Else If Job.JobName = "paarungen" Then
            Log("JobName: "&Job.JobName&"/Response:" & res)
        Else If Job.JobName = "Init" Then
            Log("JobName: "&Job.JobName&"/Response:" & res)
        Else
            ToastMessageShow(Job.JobName&": " & Job.GetString, True)
        End If
        Dim resmap As Map
        resmap.Initialize
        resmap.Put("Job",Job)
        resmap.Put("Success",Job.Success)
        resmap.Put("Result",Job.GetString)
        jobresults.Add(resmap)
        lv.AddSingleLine(Job.JobName)
        lv.SetSelection(lv.Size-1)   

        If joblist.Size > 0 Then
            Label1.Text = "Executing Job "&joblist.Get(0)&"..."
            ExecuteRemoteQuery(joblist.Get(0),joblist.Get(0))
        Else
            Label1.Text = "All Jobs are done"
            Log("All Jobs are done")
            For i = 0 To jobresults.Size -1
                Log(jobresults.Get(i))
            Next
        End If

    Else
        Dim resmap As Map
        resmap.Initialize
        resmap.Put("Job",Job)
        resmap.Put("Success",Job.Success)
        resmap.Put("Exception","Error: " & Job.ErrorMessage)
        jobresults.Add(resmap)
        lv.AddTwoLines(Job.JobName, Job.ErrorMessage)
        lv.SetSelection(lv.Size-1)   
        'ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub
 

Attachments

  • jobqueue.zip
    9.1 KB · Views: 309
Upvote 0

johnB

Active Member
Licensed User
Longtime User
Ok, then i will show a small example


B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")
    lv.FastScrollEnabled = True
    lv.SingleLineLayout.ItemHeight = 30dip
  lv.SingleLineLayout.Label.TextSize = 12
  lv.SingleLineLayout.Label.TextColor = Colors.Green
  lv.SingleLineLayout.Label.Gravity = Gravity.CENTER
    lv.TwoLinesLayout.ItemHeight = 60dip
    lv.TwoLinesLayout.Label.TextSize = 10
    lv.TwoLinesLayout.Label.TextColor = Colors.Red
    lv.TwoLinesLayout.Label.Gravity = Gravity.CENTER
    lv.TwoLinesLayout.SecondLabel.TextSize =12
    lv.TwoLinesLayout.SecondLabel.TextColor = Colors.Red
    lv.TwoLinesLayout.SecondLabel.Typeface = Typeface.DEFAULT_BOLD
    joblist.Initialize
    jobresults.Initialize
    If FirstTime Then
  End If
    ' You can fill this list with the jobs you have to do...
    joblist.Add("dummy")
    joblist.Add("dfghdfgd")
    joblist.Add("dfgertzer")
    joblist.Add("rtertertet")
    joblist.Add("tewtwete")
    joblist.Add("init")
    joblist.Add("tabellen")
    joblist.Add("paarungen")
  
  
    If joblist.Size > 0 Then
        Label1.Text = "Executing Job "&joblist.Get(0)&"..."
        ExecuteRemoteQuery(joblist.Get(0),joblist.Get(0))
        ' the further logic goe on in sub FTP_DownloadCompleted
    End If
End Sub

Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub ExecuteRemoteQuery(Query As String, JobName As String)
    Dim job As HttpJob
    Dim dummy As String
    job.Initialize(JobName, Me)
    job.download2("http://vdfb.de/b4a/", Array As String( _
        "action", Query _
    ))
End Sub
Sub JobDone(Job As HttpJob)
    ProgressDialogHide
    ' Delete the topmost job in ftpjobs
    If joblist.Size > 0 Then
        joblist.RemoveAt(0)
    End If

    If Job.Success Then
        Dim res As String
        res = Job.GetString
        If Job.JobName = "tabellen" Then
            Log("JobName: "&Job.JobName&"/Response:" & res)
        Else If Job.JobName = "paarungen" Then
            Log("JobName: "&Job.JobName&"/Response:" & res)
        Else If Job.JobName = "Init" Then
            Log("JobName: "&Job.JobName&"/Response:" & res)
        Else
            ToastMessageShow(Job.JobName&": " & Job.GetString, True)
        End If
        Dim resmap As Map
        resmap.Initialize
        resmap.Put("Job",Job)
        resmap.Put("Success",Job.Success)
        resmap.Put("Result",Job.GetString)
        jobresults.Add(resmap)
        lv.AddSingleLine(Job.JobName)
        lv.SetSelection(lv.Size-1)  

        If joblist.Size > 0 Then
            Label1.Text = "Executing Job "&joblist.Get(0)&"..."
            ExecuteRemoteQuery(joblist.Get(0),joblist.Get(0))
        Else
            Label1.Text = "All Jobs are done"
            Log("All Jobs are done")
            For i = 0 To jobresults.Size -1
                Log(jobresults.Get(i))
            Next
        End If

    Else
        Dim resmap As Map
        resmap.Initialize
        resmap.Put("Job",Job)
        resmap.Put("Success",Job.Success)
        resmap.Put("Exception","Error: " & Job.ErrorMessage)
        jobresults.Add(resmap)
        lv.AddTwoLines(Job.JobName, Job.ErrorMessage)
        lv.SetSelection(lv.Size-1)  
        'ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub

Sorry if this seems stupid or I have misunderstood something but doesn't this code assume that the jobs are returned in the same order that they are submitted, my understanding and experience is that they aren't necessarily returned in the same order.
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
Sorry if this seems stupid or I have misunderstood something but doesn't this code assume that the jobs are returned in the same order that they are submitted, my understanding and experience is that they aren't necessarily returned in the same order.


I had the same issue initially, back in the early days of RDC.
I fired off many RDC jobs procedurally, only to be tripped up because the order wasn't guaranteed.
Then Erel pointed out to ensure order, call the next Job on Success of the previous.

As Don stated, his example ensures order... The next job cannot start unless the previous succeeds. Very useful.
 
Upvote 0

johnB

Active Member
Licensed User
Longtime User
Thanks Harris for your further explanation, I misunderstood something in Don's code. Sorry for the delay in reply but for some reason I missed your post
 
Upvote 0
Top