Skip to content Skip to sidebar Skip to footer

Android Locationlistener Not Stopping Gps Use

In my service, in some scenarios I can't stop the GPS from searching and draining the device battery. LocationListenerAgent.java @Override public void onCreate() { thisContext

Solution 1:

I solved my issue. I know I didn't mention mapview in the original post but if you are also using MapView the solution is that mapview can use a GPS service unrelated to your own gps location listening service.

In your mapview

private MyLocationOverlay currLocationOverlay;

@Override
protected void onStop() {
    if(currLocationOverlay!=null)
        currLocationOverlay.disableMyLocation();
    super.onStop();
}
@Override
protected void onDestroy() {
    if(currLocationOverlay!=null)
        currLocationOverlay.disableMyLocation();
    stopService(new Intent(this, LocationListenerAgent.class));
    super.onDestroy();
}

Solution 2:

Based on the code you posted, I think you are not removing the location updates.

In your onDestroy() method it should be:

lmgrNet.removeUpdates(networkListener);
lmgrNet.removeUpdates(gpsListener);

Solution 3:

You can Also Stop like this

stopService(new Intent(AlertsActivity.this,PollingService.class)); android.os.Process.killProcess(android.os.Process.myPid());

Post a Comment for "Android Locationlistener Not Stopping Gps Use"