Application is not receiving location updates while its in background

39 views Asked by At

The Main aim of my application is to trace the path on the map in realtime which the user traverses regardless of the fact that the user has opened the application or not.

With the help of a service I am able to request the location updates i.e. the current location of the user and broadcast them to my MainActivity to trace the path accordingly.

1

There are 1 answers

10
MarkWalczak On

You should use ForegroundService instead of Serviceand call startForegroundService() when you want to start it.

Next in this new ForegroundService in onCreate method call startForeground(). With startForeground you have to pass a notification to inform the user that service is running.

Another problem is that many devices use different kind of tricks to protect battery and try to kill working services.

To track location for a long time You should try to get users permission to disable battery optimization.