Android Question Please, how to create two httpjob

Alisson

Active Member
Licensed User
Hello.

I try create two httpjob, but i not like use.
HttpJob1
B4X:
Dim reg As HttpJob
        reg.Initialize("Login", Me)
        reg.Download2("http://192.168.0.244/conection.php", _
        Array As String("imei", imei))

Sub JobDone (Job As HttpJob)
    ProgressDialogHide
    If Job.Success = True Then
        Dim ret As String
        Dim act As String    
        ret = Job.GetString     
        Dim parser As JSONParser
        parser.Initialize(ret)    
        act = parser.NextValue
        If act = "Not Found" Then
        
        
        Else If act = "Not Activated" Then
            StartActivity("register")
            Activity.Finish
               
        Else If act = "Error" Then
            ToastMessageShow("Login failed", True)
            Else If act = "1" Then
                StartActivity("wait")
                Activity.Finish
            Else If act = "2" Then
                StartActivity("blocked")
                Activity.Finish
            File.Delete(File.DirRootExternal,"folder/file.mdl")
            StartActivity("blocked")
            Activity.Finish
            Else If act = "free" Then
                If i = "0" Then
                    StartActivity("online")
                    Activity.Finish
                    Else
            StartActivity("config")
            Activity.Finish
            End If
        End If
    Else
        'Log("Error: " & Job.ErrorMessage)
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub

I need to two httpjob. Example:

httpjob2

B4X:
 Dim Regemail As HttpJob
    Regemail.Initialize("Regemail", Me)
    imei = pid.GetDeviceId
    Regemail.Download2("http://192.168.0.244/signup.php", _
      Array As String("Action", "Regemail", _
      "UserID", txtUserID.Text, _
      "Nome", txtCPF.Text, _
      "Email", txtEmail.Text))
    ProgressDialogShow("Register...")
End Sub

Sub JobDone (Job As HttpJob)
    ProgressDialogHide
    If Job.Success Then
    Dim res As String, action As String
        res = Job.GetString
        'Log("Back from Job:" & Job.JobName  & ", Success = " & Job.Success)
        'Log("Response from server: " & res)  
    
        Dim parser As JSONParser
        parser.Initialize(res)
            
        Select Job.JobName
            Case "Regemail"
                action = parser.NextValue
                If action = "Mail" Then
                Else If action = "MailInUse" Then
                    Msgbox("The user '" & txtUserID.Text & "' or email (" & txtEmail.Text & ") use", "Registration")
                Else
                Activity.LoadLayout("config")
                End If
        End Select
    Else
        'Log("Error: " & Job.ErrorMessage)
        ToastMessageShow("Erro: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub

Please, how can join the two code?

Thanks
 

DonManfred

Expert
Licensed User
Longtime User
something like

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Dim imei As String = "12345"
    Dim reg As HttpJob
    reg.Initialize("Login", Me)
  reg.Tag = "Login"
    reg.Download2("http://192.168.0.244/conection.php", _
        Array As String("imei", imei))
       

    Dim Regemail As HttpJob
  Regemail.Initialize("Regemail", Me)
  Regemail.Tag = "Regemail"
    imei = pid.GetDeviceId
  Regemail.Download2("http://192.168.0.244/signup.php", _
   Array As String("Action", "Regemail", _
      "UserID", txtUserID.Text, _
      "Nome", txtCPF.Text, _
      "Email", txtEmail.Text))
End Sub
Sub JobDone (Job As HttpJob)
    ProgressDialogHide
    If Job.Success Then
        'Log("Back from Job:" & Job.JobName  & ", Success = " & Job.Success)
        'Log("Response from server: " & res) 
           
        Select Job.JobName
            Case "Login"
                            '
                        Dim res As String, action As String
                    res = Job.GetString
   
                    Dim parser As JSONParser
                    parser.Initialize(res)
            Case "Regemail"
                        Dim res As String, action As String
                    res = Job.GetString
   
                    Dim parser As JSONParser
                    parser.Initialize(res)
                action = parser.NextValue
                If action = "Mail" Then
                Else If action = "MailInUse" Then
                    Msgbox("The user '" & txtUserID.Text & "' or email (" & txtEmail.Text & ") use", "Registration")
                Else
                Activity.LoadLayout("config")
                End If
        End Select
    Else
        'Log("Error: " & Job.ErrorMessage)
        ToastMessageShow("Erro: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub
 
Upvote 0
Top