D
Deleted member 103
Guest
Hi,
With my app I create a connection to a Bluetooth device.
All bluetooth routine are included in a classe.
The class is initialized in starter service.
The connection is started in the Activity Main.
When you quit the Activity Main, the Bluetooth connection is closed.
If I now start the app again and want to reconnect the Bluetooth device, then comes this error message: java.io.IOException: read failed, socket might closed or timeout, read ret: -1
Only if I add "ExitApplication" when quitting the Activity Main, I can connect the Bluetooth device with no problems at the next start.
How should I close the Bluetooth connection so that there are no problems with the new connection at the next start?
With my app I create a connection to a Bluetooth device.
All bluetooth routine are included in a classe.
The class is initialized in starter service.
B4X:
Sub Process_Globals
Public bluetooth As clsBluetooth
End Sub
Sub Service_Create
'Bluetooth für die Externe Taste initialisieren.
bluetooth.Initialize
End Sub
The connection is started in the Activity Main.
B4X:
Sub mnuBtButton_Click
If Starter.bluetooth.IsBtConnected Then ToastMessageShow(Starter.language.value("strBluetoothButtonIsConnected"), True)
Else
Starter.bluetooth.ConnectBtButton
End If
End Sub
When you quit the Activity Main, the Bluetooth connection is closed.
B4X:
Sub Activity_Pause (UserClosed As Boolean)
If UserClosed Then
'Bluetooth verbindung aufheben
Starter.bluetooth.DestroyConnection
End If
End Sub
'Classe clsBluetooth
Public Sub Initialize
IsOldAdminEnabled = False
IsBtConnected = False
admin.Initialize("admin")
serial1.Initialize("serial1")
tmpList.Initialize
foundDevices.Initialize
If mBBL.HasFeature("android.hardware.bluetooth") Then
'Festhalten ob Bluetooth beim Start eingeschaltet ist.
Try
If admin.IsEnabled Then
IsOldAdminEnabled = True
End If
Catch
Log("Bluetooth-Initialize ERRROR: " & LastException)
End Try
End If
End Sub
Public Sub DestroyConnection
IsBtConnected = False
If serial1.IsInitialized Then serial1.Disconnect
If AStream.IsInitialized Then AStream.Close
'Bluetooth nur dann ausschalten wenn beim Start ausgeschaltet war.
If admin.IsInitialized And Not(IsOldAdminEnabled) Then admin.Disable
End Sub
If I now start the app again and want to reconnect the Bluetooth device, then comes this error message: java.io.IOException: read failed, socket might closed or timeout, read ret: -1
Only if I add "ExitApplication" when quitting the Activity Main, I can connect the Bluetooth device with no problems at the next start.
How should I close the Bluetooth connection so that there are no problems with the new connection at the next start?