Skip to content

Prevent duplicate GPS stream subscriptions on restart#6

Open
robekl wants to merge 1 commit intoMeshMapper:devfrom
robekl:fix/gps-startwatching-single-subscription
Open

Prevent duplicate GPS stream subscriptions on restart#6
robekl wants to merge 1 commit intoMeshMapper:devfrom
robekl:fix/gps-startwatching-single-subscription

Conversation

@robekl
Copy link

@robekl robekl commented Mar 4, 2026

Summary

Makes GpsService.startWatching() idempotent by preventing multiple concurrent GPS position stream subscriptions.

Problem

startWatching() could be called multiple times (for example, after permission flows), but it created a new getPositionStream subscription without first cancelling the previous one.
This risks duplicate location events, extra processing, and increased battery usage.

Changes

  • In startWatching():
    • detect existing _positionSubscription
    • cancel and null it before creating a new subscription
    • added log line for watcher restart path

Why this works

At most one active position stream subscription is maintained, so repeated startWatching() calls restart cleanly instead of stacking listeners.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant