Skip to content Skip to sidebar Skip to footer

How To Keep Background Gps Service Alive

I'm trying to have a background gps location listener as a service that can be used by all activities in my app. It should also be scanning for locations until I 'kill' it. However

Solution 1:

However I realized that after a couple of hours the gps service gets killed and I can't get anymore locations.

First, it is an exceptionally bad idea to keep GPS powered on all of the time, as the user's battery life will suffer greatly. Your application needs to offer tremendous value (e.g., Google Navigation) to warrant this power cost.

Second, never register a listener from an IntentService. Once onHandleIntent() ends, the service shuts down... but you leak your registered listener. This effectively keeps a background thread going. However, since you have no active components, Android eventually will terminate your process.

Post a Comment for "How To Keep Background Gps Service Alive"