From 8b58751667a190c14ee72d641885454f94449280 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Wed, 5 Aug 2020 16:48:16 +0300 Subject: [PATCH] Add WeakReference for activity inside snackbar --- .../plus/measurementtool/MeasurementToolFragment.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index f3f6f64d50..297c01d102 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -81,6 +81,7 @@ import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControll import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarView; import java.io.File; +import java.lang.ref.WeakReference; import java.text.MessageFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -1591,7 +1592,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { } private void onGpxSaved(Exception warning) { - final MapActivity mapActivity = getMapActivity(); + MapActivity mapActivity = getMapActivity(); if (mapActivity == null) { return; } @@ -1605,13 +1606,15 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { dismiss(mapActivity); } else { if (close) { + final WeakReference mapActivityRef = new WeakReference<>(mapActivity); snackbar = Snackbar.make(mapActivity.getLayout(), MessageFormat.format(getString(R.string.gpx_saved_sucessfully), toSave.getName()), Snackbar.LENGTH_LONG) .setAction(R.string.shared_string_rename, new View.OnClickListener() { @Override public void onClick(View view) { - if (AndroidUtils.isActivityNotDestroyed(mapActivity)) { + MapActivity mapActivity = mapActivityRef.get(); + if (mapActivity != null && AndroidUtils.isActivityNotDestroyed(mapActivity)) { FileUtils.renameFile(mapActivity, toSave, null); } }