Android Question Ending a Service with Cleanup Code

bocker77

Active Member
Licensed User
Longtime User
I am wondering if this is the correct code to use to end a Bluetooth Service or if somehow I need to wait until the code in the Service is complete before continuing. In other words does the next instruction wait until the called sub in the Service is done. I don't want to cut the legs out from under the Service before it is done cleaning up.

In Activity:
B4X:
Sub btnEndGame_Click
    iChoice = Msgbox2("Confirm exiting the game", CMN.strGameName, "Yes", "", "No", bmpQuestion)
    If iChoice = DialogResponse.POSITIVE Then
        CallSub(BlueToothService, "CloseBlueToothConnection")
        StopService(BlueToothService)
        Activity.Finish
    Else
        Return
    End If
End Sub
In Service:
B4X:
Sub CloseBlueToothConnection
    bluetoothadmin.Disable
    AStreams.Close
    serial.Disconnect
    ToastMessageShow("BlueTooth connection closed", False)
End Sub
 
Top