Android Question Error occurred

AndrewChan0513

Member
Licensed User
Longtime User
It's always pop the error occured message box out,
and sometimes, the function will not work also,
but if I just use HttpUtils is nth error..
But I need the timeout function for if take too long I need it drop the connection immediately then start the new http get..
I sew seems to just HttpUtils2 have timeout function, so I change to use httputils2, then I got this error

Screenshot_2014_10_21_21_57_25.png

the error is not popup every time..
Is just sometimes popup..
and sometimes will not popup in 5-10 mins..


B4X:
Sub Process_Globals
Dim chb As String
Dim TimerN As Int
Dim Job1, Job2 As HttpJob
Dim s As String
Dim SMS1 As PhoneSms
      Dim Timer1 As Timer
      Timer1.Initialize("Timer1",500)
End Sub

Sub Globals
    Private EditText1 As EditText
    Private EditText2 As EditText
    Private EditText3 As EditText
    Private Label1 As Label
    Private Label2 As Label
    Private Label3 As Label
    Private EditText4 As EditText
    Private Spinner1 As Spinner
    Private Label6 As Label
    Private EditText5 As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Main")
    Spinner1.AddAll(Array As String("1","2","3","4","5","6"))
    StartService(s1)
    EditText1.Text = StateManager.GetSetting2("user","")
    EditText2.Text = StateManager.GetSetting2("pass","")
    Spinner1.SelectedIndex = StateManager.GetSetting2("pc","0")
    EditText5.Text = "64500366"
End Sub

Sub Timer1_Tick
   If TimerN = 0 Then
          TimerN = 1
          DateTime.DateFormat="hh:mm:ss"
          Label6.Text = "[" & DateTime.Date(DateTime.now) & "]" & "Checking sms code from bot."
        chb = "http://xxx1/xxx.php?username=" &  EditText1.Text & "&password=" &  EditText2.Text & "&pc=" & Spinner1.SelectedItem
        Job2.Initialize("Job2", Me)
          Job2.Download(chb)
        Job2.GetRequest.Timeout = 1000
   Else If TimerN = 1 Then
          TimerN = 0
          DateTime.DateFormat="hh:mm:ss"
          Label6.Text = "[" & DateTime.Date(DateTime.now) & "]" & "Checking sms code from bot."
        chb = "http://xxx2/xxx.php?username=" &  EditText1.Text & "&password=" &  EditText2.Text & "&pc=" & Spinner1.SelectedItem
        Job2.Initialize("Job2", Me)
          Job2.Download(chb)
        Job2.GetRequest.Timeout = 1000
   End If
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub show_msg
    EditText4.Text = s1.TestStr
        chb = "http://xxx/xxx.php?username=" &  EditText1.Text & "&password=" &  EditText2.Text & "&pc=" & Spinner1.SelectedItem & "&sms=" & EditText4.Text
        Job1.Initialize("Job1", Me)
          Job1.Download(chb)
End Sub

Sub JobDone (Job As HttpJob)
   'Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   If Job.Success = True Then
      Select Job.JobName
         Case "Job1"
             s = Job.GetString
             Msgbox(s,"完成")
         Case "Job2"
             s = Job.GetString
             'Msgbox(s,"test")
                If s.Length > 11 Then
                    EditText3.Text = s.SubString(s.Length - 12 + 1)
                    Timer1.Enabled = False
                    SMS1.Send("64500366",s.SubString(s.Length - 12 + 1))
                      DateTime.DateFormat="hh:mm:ss"
                      Label6.Text = "[" & DateTime.Date(DateTime.now) & "]Done!! Sended " & s.SubString(s.Length - 12 + 1) & " to Apple."
                End If
      End Select
   Else
      Log("Error: " & Job.ErrorMessage)
      ToastMessageShow("Error: " & Job.ErrorMessage, True)
   End If
   Job.Release
End Sub


Sub Button2_Click
      Timer1.Enabled = True
    TimerN = 0
End Sub
Sub Button1_Click
    StateManager.SaveState(Activity, "Main")
    StateManager.SetSetting("user",EditText1.Text)
    StateManager.SetSetting("pass",EditText2.Text)
    StateManager.SetSetting("pc",Spinner1.SelectedIndex)
    StateManager.SaveSettings
End Sub
 
Top