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) {