Android Question Timer is not called (upload with multipartpost.php)

grafsoft

Well-Known Member
Licensed User
Longtime User
I want to upload some filexs to a server. Mostly, the code behaves well. But sometimes, the upload lasts endlessly. Therefore I have initialized a timer with 10 seconds (Timer1.Initialize("Timer1", 10000)).

But the sub timer1_tick is never called. hc_ResponseError is also not called.

B4X:
Sub doit
   Dim li as list ...
li.initialize
   For i=1 To files.Size
     ' files.Add (l.get(i-1))
     Dim t As String
     Dim fd As FileData
     t=(files.get(i-1))
     fd.Initialize
     fd.Dir = Main.outdir
     fd.FileName = t
     fd.KeyName = t
     Log ("dnld " & t)
     fd.ContentType = "application/octet-stream"
     li.Add(fd)
   Next
   Dim NV As Map
  NV.Initialize
  NV.Put("action", "upload")
  Dim req As OkHttpRequest
  req = MultipartPost.CreatePostRequest(Main.hostname & "multipartpost.php", NV, li)
  hc.Execute(req, 1)
   
End Sub

Sub hc_ResponseError (Response As OkHttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
'  Log("error: " & Response.GetString("utf8") & " " & StatusCode)
   
  If Response <> Null Then
     Log("error: " & Response.ErrorResponse & " " & StatusCode)
     If Msgbox2 (Basis.t_timeout,"",Basis.t_yes,"",Basis.t_no,Null) = DialogResponse.POSITIVE Then
       doit
     Else
       uploadrunning=False
       Activity.finish
       Return
     End If
  End If
   
End Sub
Sub hc_ResponseSuccess (Response As OkHttpResponse, TaskId As Int)
     out.InitializeToBytesArray(0) ' I expect less than 2000 bytes here
     Response.GetAsynchronously("Response", out, True, TaskId)
   Dim another_buffer () As Byte
  another_buffer = out.ToBytesArray
  Log (BytesToString(another_buffer, 0, another_buffer.Length, "UTF8"))

     'Log("response: " & Response.GetString("utf8") )
  'Msgbox(Response, "")
  ' Response.Release
End Sub

Sub Response_StreamFinish (Success As Boolean, TaskId As Int)
  Dim another_buffer () As Byte
  another_buffer = out.ToBytesArray
  Log (BytesToString(another_buffer, 0, another_buffer.Length, "UTF8"))
   
   ToastMessageShow (Basis.t_done,True)
   uploadrunning=False
   Activity.Finish
End Sub


Sub Timer1_Tick
   doit
end sub
 

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello,
Hard to see as we don't have the whole code but, you do a Timer1.Enabled=True elsewhere ?
 
Upvote 0
Top