Android Question How to kill a service permanently

grafsoft

Well-Known Member
Licensed User
Longtime User
Hi,

I am using MyLocation as a basis for my project.

I want to stop and kill the service when the user stops the program.

This is what I tried:

In tracker.bas:

B4X:
Sub Service_Destroy
    ' Service.StopAutomaticForeground 
    CancelScheduledService(Me)
    StopService (Me)
    Service.StopForeground(1)
    ToastMessageShow("Close Service", True  )
    Log ("Stopservice")
    lock.ReleasePartialLock
End Sub

In Main:
B4X:
Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed Then 
       StopService (Tracker)
        Log ("Tracker stopped")
    End If
End Sub

Pls help.
 

Gandalf

Member
Licensed User
Longtime User
Try creating separate Sub in Tracker which contains (exactly in this order):
B4X:
lock.ReleasePartialLock
CancelScheduledService(Me)
Service.StopForeground(1)
StopService (Me)

Then call this sub from Main Activity_Pause.
 
Upvote 1
Top