I have developed an application that tracks user's location and records the distance traveled by the user. To make the app robust, I have used foreground service that spawns a thread with a handler inside it. The FusedLocationProvider sends location updates to the thread via handler and thread calculates distance traveled and sends the location to the server.
The service is closed when the user closes the application.
However, the service stops sometimes when the device is kept in sleep mode. How can I make the foreground service always running as long as the user does not manually close the application?