From 6417e995d30a624358479501bde40f0aab771cca Mon Sep 17 00:00:00 2001 From: max-klaus Date: Wed, 20 Jan 2021 10:38:57 +0300 Subject: [PATCH] Fix first time location get --- OsmAnd/src/net/osmand/plus/activities/MapActivity.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index a94997caaa..eb6dcbfbb7 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -349,17 +349,19 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven if (!settings.isLastKnownMapLocation()) { // show first time when application ran + final WeakReference activityRef = new WeakReference<>(this); net.osmand.Location location = app.getLocationProvider().getFirstTimeRunDefaultLocation(new OsmAndLocationListener() { @Override public void updateLocation(Location location) { - if (app.getLocationProvider().getLastKnownLocation() == null) { - setMapInitialLatLon(location); + MapActivity a = activityRef.get(); + if (AndroidUtils.isActivityNotDestroyed(a) && app.getLocationProvider().getLastKnownLocation() == null) { + setMapInitialLatLon(a.mapView, location); } } }); mapViewTrackingUtilities.setMapLinkedToLocation(true); if (location != null) { - setMapInitialLatLon(location); + setMapInitialLatLon(mapView, location); } } addDialogProvider(mapActions); @@ -384,7 +386,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven mIsDestroyed = false; } - private void setMapInitialLatLon(@Nullable Location location) { + private void setMapInitialLatLon(@NonNull OsmandMapTileView mapView, @Nullable Location location) { if (location != null) { mapView.setLatLon(location.getLatitude(), location.getLongitude()); mapView.setIntZoom(14);