From 104a200d6856e8201b3e6d45a3ba5cc0e1c7e445 Mon Sep 17 00:00:00 2001 From: Armin Date: Tue, 27 Jun 2023 09:19:26 +0200 Subject: [PATCH] [RFR-630] Ensure laucher is not called after fragment is detached --- .../cyface/app/r4r/capturing/marker/MarkerFragment.kt | 5 +++++ utils/src/main/kotlin/de/cyface/app/utils/Map.kt | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ui/r4r/src/main/kotlin/de/cyface/app/r4r/capturing/marker/MarkerFragment.kt b/ui/r4r/src/main/kotlin/de/cyface/app/r4r/capturing/marker/MarkerFragment.kt index 407ce00f..3ad5a73e 100644 --- a/ui/r4r/src/main/kotlin/de/cyface/app/r4r/capturing/marker/MarkerFragment.kt +++ b/ui/r4r/src/main/kotlin/de/cyface/app/r4r/capturing/marker/MarkerFragment.kt @@ -129,6 +129,11 @@ class MarkerFragment : Fragment() { _binding = null } + override fun onDestroy() { + super.onDestroy() + map?.onDestroy() + } + companion object { fun eventPassed(): Boolean { val now = Calendar.getInstance() diff --git a/utils/src/main/kotlin/de/cyface/app/utils/Map.kt b/utils/src/main/kotlin/de/cyface/app/utils/Map.kt index 19bc1e2e..b04f6d74 100644 --- a/utils/src/main/kotlin/de/cyface/app/utils/Map.kt +++ b/utils/src/main/kotlin/de/cyface/app/utils/Map.kt @@ -73,7 +73,7 @@ class Map( private val view: MapView, savedInstanceState: Bundle?, onMapReadyRunnable: Runnable, - permissionLauncher: ActivityResultLauncher>, + private var permissionLauncher: ActivityResultLauncher>?, private val ignoreAutoZoom: Boolean = false ) : OnMapReadyCallback, LocationListener { /** @@ -131,7 +131,8 @@ class Map( view.onCreate(savedInstanceState) val activity = view.context as Activity applicationContext = activity.applicationContext - permissionLauncher.launch( + // Ensure launcher is not called after parent fragment was destroyed [RFR-630] + permissionLauncher?.launch( arrayOf( Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION @@ -449,6 +450,11 @@ class Map( stopLocationUpdates() } + fun onDestroy() { + // Ensure launcher is not called after parent fragment was destroyed [RFR-630] + permissionLauncher = null + } + override fun onLocationChanged(location: Location) { // This is used by `ui/cyface`, the `ui/r4r` uses `onLocationResult` if (isAutoCenterMapEnabled && !ignoreAutoZoom) {