TrackRecordingService: must be stopped via TrackRecordingServiceConnection and handles Preference changes.

This commit is contained in:
Dennis Guse
2023-08-08 23:22:35 +02:00
parent 0a5b46655a
commit 4d5c59be96
10 changed files with 96 additions and 101 deletions
@@ -48,7 +48,8 @@ public class GPSManager implements SensorConnector, LocationListenerCompat, GpsS
this.context = context;
this.handler = handler;
PreferencesUtils.registerOnSharedPreferenceChangeListener(this);
onSharedPreferenceChanged(null, null);
gpsStatusManager = new GpsStatusManager(context, this, handler);
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
registerLocationListener();
@@ -62,20 +63,15 @@ public class GPSManager implements SensorConnector, LocationListenerCompat, GpsS
@SuppressWarnings({"MissingPermission"})
//TODO upgrade to AGP7.0.0/API31 started complaining about removeUpdates.
public void stop(Context context) {
if (locationManager != null && context != null) {
if (PermissionRequester.GPS.hasPermission(context)) {
LocationManagerCompat.removeUpdates(locationManager, this);
}
locationManager = null;
context = null;
handler = null;
if (locationManager != null) {
LocationManagerCompat.removeUpdates(locationManager, this);
}
locationManager = null;
this.context = null;
handler = null;
if (gpsStatusManager != null) {
gpsStatusManager.stop();
gpsStatusManager = null;
}
PreferencesUtils.unregisterOnSharedPreferenceChangeListener(this);
gpsStatusManager.stop();
gpsStatusManager = null;
}
@Override