Arf Well-Known Member Licensed User Longtime User Feb 28, 2014 #1 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: Code: Copy Sub Activity_Pause (UserClosed As Boolean) If UserClosed = True Then StopService(Unit_Comms) End If End Sub In Unit_Comms: Code: Copy 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
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: Code: Copy Sub Activity_Pause (UserClosed As Boolean) If UserClosed = True Then StopService(Unit_Comms) End If End Sub In Unit_Comms: Code: Copy 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
JTmartins Active Member Licensed User Longtime User Feb 28, 2014 #2 The service_destroy, does not actualy makes the service to be destroyed (disapear from task manager), as far as I've understood it Android decides when it should be destroyed and only then it disapears from the task manager. It may take some time. Upvote 0
The service_destroy, does not actualy makes the service to be destroyed (disapear from task manager), as far as I've understood it Android decides when it should be destroyed and only then it disapears from the task manager. It may take some time.
Erel B4X founder Staff member Licensed User Longtime User Feb 28, 2014 #3 JTmartins said: The service_destroy, does not actualy makes the service to be destroyed (disapear from task manager), as far as I've understood it Android decides when it should be destroyed and only then it disapears from the task manager. It may take some time. Click to expand... That is correct. You can call ExitApplication to kill the process. In most cases it will only cause trouble. Upvote 0
JTmartins said: The service_destroy, does not actualy makes the service to be destroyed (disapear from task manager), as far as I've understood it Android decides when it should be destroyed and only then it disapears from the task manager. It may take some time. Click to expand... That is correct. You can call ExitApplication to kill the process. In most cases it will only cause trouble.
Arf Well-Known Member Licensed User Longtime User Feb 28, 2014 #4 OK then. It looks like it's best for my app to just leave the service handling bluetooth connection running when the app is exited then. What if another app gets run by the user that requires bluetooth? Will my service be terminated? I'm trying to see if I can detect whether my sevice is running or not in Main's Activity_Create. How can i check if my service (Comms_Unit) is running or not? Upvote 0
OK then. It looks like it's best for my app to just leave the service handling bluetooth connection running when the app is exited then. What if another app gets run by the user that requires bluetooth? Will my service be terminated? I'm trying to see if I can detect whether my sevice is running or not in Main's Activity_Create. How can i check if my service (Comms_Unit) is running or not?
Arf Well-Known Member Licensed User Longtime User Feb 28, 2014 #5 Found how to check if service is runnning, so never mind Upvote 0