i am trying to run tcp connection in a service all works fine until the app goes to background
i use callsub to update GUI when i bring the app to background the gui is not getting updated
i thought to handle this by using a list to hold on the received data and handle them when i go back to foreground
i do something like this in the service
and i do this in the main activity
some times app crash when its comes back from background and the data gets conflicted
i feel its wrong way to handle the background operations how could i handle background operations with asyncstream correctly ?
i use callsub to update GUI when i bring the app to background the gui is not getting updated
i thought to handle this by using a list to hold on the received data and handle them when i go back to foreground
i do something like this in the service
B4X:
Public Sub handlebgcmd
If CMDLISTS.Size > 0 Then
For i = 0 To CMDLISTS.Size - 1
Handlcmdstrings(CMDLISTS.Get(i))
Sleep(0)
Next
CMDLISTS.Clear
End If
isbackground = False
End Sub
Public Sub Handlcmdstrings(CMDS As String)
Dim paramnum() As String
paramnum = Regex.Split("\&", CMDS)
If paramnum(0) = "ver" Then
Log(paramnum(1))
Else If paramnum(0) = "connected" Then
CallSub2(Main,"Displayconnect",paramnum(1))
End If
End Sub
Public Sub NEWDATA(data() As Byte)
Dim arrvmsg As String
arrvmsg = BytesToString(data, 0, data.Length, "UTF-8")
arrvmsg = arrvmsg.Trim
If arrvmsg.Length = 0 Then
Log("Error")
Return
End If
If isbackground = True Then
CMDLISTS.Add(arrvmsg)
Return
End If
Handlcmdstrings(arrvmsg)
End Sub
and i do this in the main activity
B4X:
Sub Activity_Resume
CallSub(Service, "handlebgcmd")
End Sub
Sub Activity_Pause (UserClosed As Boolean)
If UserClosed = True Then
StopService(Service)
Else
If UserClosed = False Then
Service.isbackground = True
End If
End If
End Sub
some times app crash when its comes back from background and the data gets conflicted
i feel its wrong way to handle the background operations how could i handle background operations with asyncstream correctly ?