Skip to content

Commit 9437cde

Browse files
committed
fix edge case
1 parent 033b1f7 commit 9437cde

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

location/src/main/kotlin/io/customer/location/LocationLifecycleObserver.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ internal class LocationLifecycleObserver(
2929
}
3030

3131
override fun onStop(owner: LifecycleOwner) {
32-
locationServices.cancelInFlightRequest()
32+
val wasCancelled = locationServices.cancelInFlightRequest()
33+
// If the GPS request was still in flight when we backgrounded,
34+
// allow onStart to retry on the next foreground entry.
35+
if (wasCancelled) {
36+
hasRequestedOnStart = false
37+
}
3338
}
3439
}

location/src/main/kotlin/io/customer/location/LocationServicesImpl.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,14 @@ internal class LocationServicesImpl(
6262
/**
6363
* Cancels any in-flight location request.
6464
* Called when the app enters background to avoid unnecessary GPS work.
65+
*
66+
* @return true if an active request was cancelled, false if nothing was in flight.
6567
*/
66-
internal fun cancelInFlightRequest() {
67-
currentLocationJob?.cancel()
68+
internal fun cancelInFlightRequest(): Boolean {
69+
val job = currentLocationJob ?: return false
6870
currentLocationJob = null
71+
job.cancel()
72+
return true
6973
}
7074

7175
companion object {

0 commit comments

Comments
 (0)