I am using the bluetooth example for test. When the app goes into the ackround (pause) then
the starter service is not receiving data anymore.
I use b4a 8.3, android 8 and I thought it should work, because
Update: Starting from B4A v8.3 the starter service will never be killed unless the whole process is killed. This means that you can always assume in your code that the starter service is running.
It is done internally by changing the starter service context to the application context.
the starter service is not receiving data anymore.
I use b4a 8.3, android 8 and I thought it should work, because
Update: Starting from B4A v8.3 the starter service will never be killed unless the whole process is killed. This means that you can always assume in your code that the starter service is running.
It is done internally by changing the starter service context to the application context.
B4X:
#Region Service Attributes
#StartAtBoot: False
#ExcludeFromLibrary: True
#End Region
Sub Process_Globals
Private serial As Serial
Private admin As BluetoothAdmin
Private ast As AsyncStreamsText
Public connected As Boolean
Public connecting As Boolean
End Sub
Sub Service_Create
serial.Initialize("serial")
admin.Initialize("admin")
End Sub
Public Sub Connect
admin.StartDiscovery
connecting = True
CallSub(Main, "SetState")
End Sub
Private Sub admin_DeviceFound (Name As String, MacAddress As String)
Log($"Device found: ${Name}"$)
If Name.Contains("central433") Or Name.Contains("zentral433") Then
Log("Trying to connect...")
admin.CancelDiscovery
serial.Connect(MacAddress)
End If
End Sub
Private Sub admin_DiscoveryFinished
connecting = False
End Sub
Private Sub Serial_Connected (Success As Boolean)
If Success Then
If ast.IsInitialized Then ast.Close
ast.Initialize(Me, "Ast", serial.InputStream, serial.OutputStream)
Log("Connected")
connected = True
Else
Log(LastException)
End If
connecting = False
CallSub(Main, "SetState")
End Sub
Public Sub SendMessage(msg() As Byte)
' Dim m As String
'
' m = BytesToString(msg,0,msg.Length,"")
'
' Log(m)
ast.astreams.Write(msg) 'sending bytes, not text
End Sub
Private Sub ast_NewText (Text As String)
CallSub2(Main, "MessageFromDevice", Text)
End Sub
Private Sub ast_Terminated
connected = False
CallSub(Main, "SetState")
End Sub
Sub Service_Start (StartingIntent As Intent)
End Sub
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub Service_Destroy
End Sub
Last edited: