Android Question GPS stop problems

jefflynn1974

Member
Licensed User
Longtime User
Hello,

I am using the GPS Libary and I have a big problem with it. After I used GPS.Start(20000,100) then the GPS icon always flashes at the statusbar after 20 seconds even I stopped it with GPS.Stop. What is the solution for this? How can I stop absolutely the GPS?

Thanks!
 
D

Deleted member 103

Guest
Hi jefflynn1974,

paste this code:
B4X:
Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed Then
        If GPS1.GPSEnabled Then
            GPS1.stop
            ExitApplication
        End If   
    End If
End Sub
 
Upvote 0

jefflynn1974

Member
Licensed User
Longtime User
Filippo, Erel!

I forgot to tell it is in a service modul which gets my GPS position in every five minutes and sends it to my server. Though I use the GPS.Stop the GPS icon flashes in every 20 seconds again and again. I can only stop this effect if I turn off the GPS manually or if I use another GPS application and exit from it.
 
Upvote 0

jefflynn1974

Member
Licensed User
Longtime User
Yes it disappears after the first running of the application but on my phone the icon flashes again and again in every 20 seconds although the program willl only use the GPS in the next 5 minutes. Could you please check this on your device? I really don't know what the hell is going on here...
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It doesn't happen here.

Anyway, try this code:
B4X:
Sub Service_Create

   If GPS1.IsInitialized = False Then GPS1.Initialize("GPS")
   If Timer2.IsInitialized = False Then Timer2.Initialize ("Timer2", 120000) '2 perc (mp-ben)
   
End Sub

Sub Service_Start (StartingIntent As Intent)
   StartServiceAt ("", DateTime.Now + 300 * 1000, True)
   GPS1.Start(0,0)
   Timer2.Enabled = True
End Sub


Sub GPS_LocationChanged (Location1 As Location)
   GPS1.stop
   latitude = Location1.latitude
   longitude = Location1.longitude
   ToastMessageShow(latitude & " " & longitude,True)
   Timer2.Enabled = False
End Sub

Sub Timer2_Tick
   Timer2.Enabled = False
   GPS1.Stop
   ToastMessageShow("No GPS",True)
End Sub
 
Upvote 0

jefflynn1974

Member
Licensed User
Longtime User
This works fine because the GPS1.Start is (0,0) not (20000,100) as in my previous code.

I used the (0,0) parameters before but in my full application it made some problems. It gave back more coordinates at the same time which is confused the app. This is why I started to use GPS1.Start(20000,100) to avoid problems and work with only one given position.

So I should just use (0,0) and there is no other solution for this situation?
 
Upvote 0

jefflynn1974

Member
Licensed User
Longtime User
I tested on three different type of devices and it seems this effect is not appearing on everyone. Unfortunately some devices nevertheless do it, I don't know why. Maybe it depends on the ROM.
 
Upvote 0
Top