Android Question LocationManager Stop Action

fbritop

Active Member
Licensed User
Longtime User
I have an APP that uses location. Location is achieved in a special service that stores locations changes to a DB.

When my app goes to the background I destroy the service and the service has:

B4X:
Sub Service_Destroy
    lm.stopGPSListening
    lm.stopMobileListening
End Sub

When it goes foreground the service is started.

Anyway, when my APP goes to background, the service is destroyed (I can see in the logs) but Android keeps the location PIN on.

Is there another whay to stop the Location Manager from using location?

Thanks
FBP
 

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello,
The way you stop the location request is the one to use. May I ask you where you initialize LM in your service's module ?
 
Upvote 0

fbritop

Active Member
Licensed User
Longtime User
B4X:
#Region  Service Attributes
    #StartAtBoot: False
#End Region

Sub Process_Globals
    Private lm As LocationManager
End Sub

Sub Service_Create
    lm.Initialize("lm")
End Sub

Sub Service_Start (StartingIntent As Intent)
    lm.requestGPSLocation
    lm.requestMobileLocation
End Sub

Sub Service_Destroy
    lm.stopGPSListening
    lm.stopMobileListening
End Sub

Sub lm_LocationChanged (Longitude As Double, Latitude As Double, Altitude As Double, Accuracy As Float, Bearing As Float, Provider As String, Speed As Float, Time As Long)
    Log("lm_LocationChanged")
End Sub
 
Upvote 0

fbritop

Active Member
Licensed User
Longtime User
One thing I notice.
When I compile in debug mode it works fine, but when I compile in Release, there is no way to stop the location manager
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
You use it correctly. The only thing I could think about is the fact that you could stop the GPS request if you get the network location. But that GPS request should be stopped when you Stop the service.
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
I was using this stuff for years... The GPS is held active on a users' count base. You activate 1 time then you must deactivate 1 time, you activate three times and you have to deactivate three times. This is my experience.
Probably you started the GPS more than 1 time. I did in the first APP I wrote...

Ciao
Mauro
 
Upvote 0
Top