forked from upstream-mirrors/OpenTracks
TrackRecordingService: must be stopped via TrackRecordingServiceConnection and handles Preference changes.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.dennisguse.opentracks.services.handlers;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.location.Location;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
@@ -23,7 +24,7 @@ import de.dennisguse.opentracks.settings.PreferencesUtils;
|
||||
/**
|
||||
* Creates TrackPoints while recording by fusing data from different sensors (e.g., GNSS, barometer, BLE sensors).
|
||||
*/
|
||||
public class TrackPointCreator {
|
||||
public class TrackPointCreator implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
private static final String TAG = TrackPointCreator.class.getSimpleName();
|
||||
|
||||
@@ -150,6 +151,11 @@ public class TrackPointCreator {
|
||||
service.newGpsStatus(gpsStatusValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, @Nullable String key) {
|
||||
sensorManager.onSharedPreferenceChanged(sharedPreferences, key);
|
||||
}
|
||||
|
||||
public interface Callback {
|
||||
/**
|
||||
* @return Was TrackPoint stored (not discarded)?
|
||||
|
||||
Reference in New Issue
Block a user