Skip to content

Commit

Permalink
[RFR-630] Ensure laucher is not called after fragment is detached
Browse files Browse the repository at this point in the history
  • Loading branch information
hb0 committed Jun 27, 2023
1 parent d821bfb commit 104a200
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 8 additions & 2 deletions utils/src/main/kotlin/de/cyface/app/utils/Map.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Map(
private val view: MapView,
savedInstanceState: Bundle?,
onMapReadyRunnable: Runnable,
permissionLauncher: ActivityResultLauncher<Array<String>>,
private var permissionLauncher: ActivityResultLauncher<Array<String>>?,
private val ignoreAutoZoom: Boolean = false
) : OnMapReadyCallback, LocationListener {
/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 104a200

Please sign in to comment.