diff --git a/src/main/java/menion/android/whereyougo/geo/location/GpsConnection.java b/src/main/java/menion/android/whereyougo/geo/location/GpsConnection.java index 2efb0f6c..aef58163 100644 --- a/src/main/java/menion/android/whereyougo/geo/location/GpsConnection.java +++ b/src/main/java/menion/android/whereyougo/geo/location/GpsConnection.java @@ -44,6 +44,7 @@ public class GpsConnection { private final MyLocationListener llGPS; private final MyLocationListener llNetwork; private final MyGpsListener gpsListener; + private final MyGnssListener gnssListener; private boolean isFixed; private Timer mGpsTimer; // temp variable for indicating whether network provider is enabled @@ -58,6 +59,7 @@ public GpsConnection(Context context) { llGPS = new MyLocationListener(); llNetwork = new MyLocationListener(); gpsListener = new MyGpsListener(); + gnssListener = new MyGnssListener(); // init basic fixing values isFixed = false; @@ -105,7 +107,6 @@ public GpsConnection(Context context) { // add new listener GPS try { if (Build.VERSION.SDK_INT >= 24) { - MyGnssListener gnssListener = new MyGnssListener(); locationManager.registerGnssStatusCallback(gnssListener); } else { locationManager.addGpsStatusListener(gpsListener); @@ -131,7 +132,11 @@ public void destroy() { if (locationManager != null) { disableNetwork(); locationManager.removeUpdates(llGPS); - locationManager.removeGpsStatusListener(gpsListener); + if (Build.VERSION.SDK_INT >= 24) { + locationManager.unregisterGnssStatusCallback(gnssListener); + } else { + locationManager.removeGpsStatusListener(gpsListener); + } locationManager = null; // XXX missing context to notify by widget ManagerNotify.toastShortMessage(R.string.gps_disabled);