Avoid concurrent modification of location listeners

This commit is contained in:
Vitaliy 2021-02-22 17:11:43 +02:00
parent f95c97ff15
commit 8af96a20b5

View file

@ -373,22 +373,30 @@ public class OsmAndLocationProvider implements SensorEventListener {
public void addLocationListener(@NonNull OsmAndLocationListener listener) { public void addLocationListener(@NonNull OsmAndLocationListener listener) {
if (!locationListeners.contains(listener)) { if (!locationListeners.contains(listener)) {
locationListeners.add(listener); List<OsmAndLocationListener> listeners = new ArrayList<>(locationListeners);
listeners.add(listener);
locationListeners = listeners;
} }
} }
public void removeLocationListener(@NonNull OsmAndLocationListener listener) { public void removeLocationListener(@NonNull OsmAndLocationListener listener) {
locationListeners.remove(listener); List<OsmAndLocationListener> listeners = new ArrayList<>(locationListeners);
listeners.remove(listener);
locationListeners = listeners;
} }
public void addCompassListener(@NonNull OsmAndCompassListener listener) { public void addCompassListener(@NonNull OsmAndCompassListener listener) {
if (!compassListeners.contains(listener)) { if (!compassListeners.contains(listener)) {
compassListeners.add(listener); List<OsmAndCompassListener> listeners = new ArrayList<>(compassListeners);
listeners.add(listener);
compassListeners = listeners;
} }
} }
public void removeCompassListener(@NonNull OsmAndCompassListener listener) { public void removeCompassListener(@NonNull OsmAndCompassListener listener) {
compassListeners.remove(listener); List<OsmAndCompassListener> listeners = new ArrayList<>(compassListeners);
listeners.remove(listener);
compassListeners = listeners;
} }
@Nullable @Nullable