This commit is contained in:
Dennis Guse
2021-07-15 18:20:33 +02:00
parent cce62c4c47
commit 0f6480197b
@@ -42,8 +42,11 @@ class LocationHandler implements LocationListener, GpsStatus.GpsStatusListener {
}
public void onStop() {
unregisterLocationListener();
locationManager = null;
if (locationManager != null) {
locationManager.removeUpdates(this);
locationManager = null;
}
if (gpsStatus != null) {
gpsStatus.stop();
gpsStatus = null;
@@ -63,9 +66,7 @@ class LocationHandler implements LocationListener, GpsStatus.GpsStatusListener {
locationListenerPolicy = new AbsoluteLocationListenerPolicy(Duration.ofSeconds(minRecordingInterval));
}
if (locationManager != null) {
registerLocationListener();
}
registerLocationListener();
}
if (PreferencesUtils.isKey(context, R.string.recording_gps_accuracy_key, key)) {
recordingGpsAccuracy = PreferencesUtils.getRecordingGPSAccuracy(sharedPreferences, context);
@@ -153,15 +154,6 @@ class LocationHandler implements LocationListener, GpsStatus.GpsStatusListener {
}
}
private void unregisterLocationListener() {
if (locationManager == null) {
Log.e(TAG, "locationManager is null.");
return;
}
locationManager.removeUpdates(this);
locationManager = null;
}
/**
* Called from {@link GpsStatus} to inform that GPS status has changed from prevStatus to currentStatus.
*