I emailed the APK (compiled in Release mode) to myself after uninstalling everything to do with my app and experimental instances, rebooted tablet and installed the APK. Everything runs fine, just one unexpected:
On exit (click exit button in app, or click the back button (allegedly)) my program should cease to be, and before it does so it should turn bluetooth off and then kill the service thread.
After either of those exit strategies I can see the bluetooth turns off, but the program is still there in the task manager.
Here are the shut-down bits of my code, have I missed anything obvious? How do I kill it completely?
in Main:
Sub Activity_Pause (UserClosed As Boolean)
If UserClosed = True Then
StopService(Unit_Comms)
End If
End Sub
In Unit_Comms:
Sub Service_Destroy
If UNIT_CONNECTED = True Then
Send_Packet(1,Null,0) 'PKT_KILL
Do While UNIT_CONNECTED = True
Loop
End If
AStream.Close
admin.CancelDiscovery
serial1.Disconnect
admin.Disable
End Sub