Android Question GPS.Stop

D

Deleted member 103

Guest
Hi,

I initialize and start GPS with the starter service, when you exit where should I stop at the best GPS, in the Main-Activity_Pause or starter service?

Question, of when is in Starter service the content of Sub "Service_Destroy" performed?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Question, of when is in Starter service the content of Sub "Service_Destroy" performed?
Never, unless you call StopService(Starter).

It depends on your app requirements. Applications are moved to the background and eventually are killed by the OS. If it makes sense to stop the GPS when the activity is paused then do it from Activity_Pause.

When the OS kills the process, it kills it immediately.
 
Upvote 0
D

Deleted member 103

Guest
Thanks for the answer.

But if I call StopService (starter) of Activity_Pause the Sub "Service_Destroy" is not performed, I see at least no log.
B4X:
Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed Then
        'Service beenden
        StopService(Starter)
    End If
End Sub

Sub Service_Destroy
    Log("Starter: Service_Destroy")
End Sub
 
Upvote 0
D

Deleted member 103

Guest
I'm not blind. :mad:
The problem is that it does not always work, here the log of 2 app. :(
###### Result of App Nr.1 ######

** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
UserClosed=true
** Service (starter) Destroy **
Starter: Service_Destroy


###### Result of App Nr.1 ######

** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
UserClosed=true
 
Upvote 0
D

Deleted member 103

Guest
OK, I've found the problem.
I have in App No.2 after "StopService(Starter)" also "ExitApplication"

B4X:
Sub Activity_Pause (UserClosed As Boolean)
   If UserClosed Then
     StopService(Starter)
     ExitApplication
   End If
End Sub
 
Upvote 0
Top