Search code examples
androidgps

GPS looses connection after 30 minutes in Android app


I use a Service to get GPS coordinates and it works well for about 30 minutes. After 30 minutes, it stops working and no more onLocationChanged occurs (sometimes even the GPS lock signal is off, too). Is there any limitation that I should consider when using continuous GPS navigation? Does the GPS get killed by the OS after a certain period?

Could it be the service that runs the GPS service? Can it be killed after 30 minutes? I start it with START_STICKY.


Solution

  • It seems that the service was killed after 30 minutes (though it was START_STICKY). I modified it by adding the following line:

    startForeGround(1234, new Notification());
    

    Using this prevents the OS from restarting the service. The only unfortunate consequence is that the battery consumption is increased, the GPS drains the phone in 6-9 hours. It is not yet clear, whether the service modification or the continuous searching when lost GPS connection made it increase.