Android Question Can't close the app?

Arf

Well-Known Member
Licensed User
Longtime User
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:
B4X:
Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed = True Then
        StopService(Unit_Comms)
    End If
End Sub

In Unit_Comms:
B4X:
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
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

Erel

B4X founder
Staff member
Licensed User
Longtime User
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.
That is correct. You can call ExitApplication to kill the process. In most cases it will only cause trouble.
 
Upvote 0

Arf

Well-Known Member
Licensed User
Longtime User
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
Cookies are required to use this site. You must accept them to continue using the site. Learn more…