react-native-background-geolocation
react-native-background-geolocation copied to clipboard
If the app has the 'display over other apps' granted, the position monitoring in background kills the app/activity.
Your Environment
- Plugin version: 4.8.0
- Platform: Android
- OS version: Android 12
- Device manufacturer / model: Google Pixel 4
- React Native version (
react-native -v): 0.66.0 - Plugin config
await BackgroundGeolocation.ready({
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_NAVIGATION,
showsBackgroundLocationIndicator: true,
distanceFilter: 0,
stopTimeout: 5,
preventSuspend: true,
heartbeatInterval: 30,
foregroundService: true,
debug: false,
logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
stopOnTerminate: true,
startOnBoot: false,
batchSync: false,
autoSync: false,
maxDaysToPersist: 3,
});
Expected Behavior
The app should continue the monitoring in background.
Actual Behavior
The app crash/is killed and no exception is thrown.
Steps to Reproduce
- add
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />in manifest - grant permission for 'display over other apps' in the device settings.
- start the app and move it to background
- start monitoring.
- the app crashes immediately.
Context
I'm trying to start position monitoring when the app is in background. The SYSTEM_ALERT_WINDOW is needed as requirement in order to start/restart the app when the device is in proximity of a paired bluetooth device.
Debug logs
Logs
2022-06-24 18:37:05.961 23024-23123/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.logger.TSLog log] [BremboInspire] | LEVEL: debug --- listenStartAutomaticMonitoring ----> BLUETOOTH - BT start Callback!
2022-06-24 18:37:06.046 23024-23123/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.logger.TSLog log] [BremboInspire] | LEVEL: debug --- START! ----> Geolocation
2022-06-24 18:37:06.341 23024-23123/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.logger.TSLog log] [BremboInspire] | LEVEL: debug --- startMonitoring ----> TRIP STARTING - BEFORE initTrip! ||| appVersion --> 0.9.0 - 90111 ||| BT --> true ||| device --> {"version":"12","framework":"react-native","model":"Pixel 4","platform":"Android","manufacturer":"Google"}
2022-06-24 18:37:07.053 23024-23123/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.adapter.TSConfig d] ℹ️ Persist config, dirty: [extras]
2022-06-24 18:37:07.076 23024-23123/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.locationmanager.util.c g]
ℹ️ LocationAuthorization: Permission granted
2022-06-24 18:37:07.080 23024-23799/it.vidiemme.brembo.oneapp.dev I/TSLocationManager: - Enable: false → true, trackingMode: 1
2022-06-24 18:37:07.083 23024-23799/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.http.HttpService startMonitoringConnectivityChanges]
🎾 Start monitoring connectivity changes
2022-06-24 18:37:07.092 23024-23799/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.device.DeviceSettings startMonitoringPowerSaveChanges]
🎾 Start monitoring powersave changes
2022-06-24 18:37:07.104 23024-23799/it.vidiemme.brembo.oneapp.dev I/TSLocationManager: [c.t.l.service.HeartbeatService start]
🎾 Start heartbeat (30s)
2022-06-24 18:37:07.105 23024-23135/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.http.HttpService a]
╔═════════════════════════════════════════════
║ 📶 Connectivity change: connected? true
╠═════════════════════════════════════════════
2022-06-24 18:37:07.115 23024-23799/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.locationmanager.util.c h]
ℹ️ LocationAuthorization: Permission granted
2022-06-24 18:37:07.118 23024-23799/it.vidiemme.brembo.oneapp.dev I/TSLocationManager: [c.t.l.service.TrackingService changePace]
🔵 setPace: false → false
2022-06-24 18:37:07.143 23024-23123/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.logger.TSLog log] [BremboInspire] | LEVEL: debug --- startMonitoring ----> TRIP dc847551-525e-4b70-aca8-d43ac7eb920d STARTED
2022-06-24 18:37:07.151 23024-23024/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.service.AbstractService start]
🎾 LocationRequestService [eventCount: 1]
2022-06-24 18:37:07.152 23024-23799/it.vidiemme.brembo.oneapp.dev I/TSLocationManager: [c.t.l.l.SingleLocationRequest startUpdatingLocation]
🔵 [SingleLocationRequest start, action: 1, requestId: 3]
2022-06-24 18:37:07.155 23024-23799/it.vidiemme.brembo.oneapp.dev I/TSLocationManager: [c.t.l.s.ActivityRecognitionService start]
🎾 Start motion-activity updates
2022-06-24 18:37:07.157 23024-23799/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.service.AbstractService finish] ⚙️︎ finish LocationRequestService [eventCount: 0, sticky: true]
2022-06-24 18:37:07.314 23024-23024/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.a.TSLocationManagerActivity execute] locationsettings
2022-06-24 18:37:07.314 23024-23024/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.adapter.TSConfig translateDesiredAccuracy] translateDesiredAccuracy (true): -2
2022-06-24 18:37:07.318 23024-23024/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.l.LifecycleManager onStart] ☯️ onStart
2022-06-24 18:37:07.335 23024-23024/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.l.LifecycleManager onResume] ☯️ onResume
2022-06-24 18:37:07.342 23024-23024/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.a.TSLocationManagerActivity stop] eventCount: 0
2022-06-24 18:37:07.395 23024-23024/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.a.BackgroundGeolocation b]
🔴 Cleared callbacks
2022-06-24 18:37:07.398 23024-23024/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.l.LifecycleManager a]
╔═════════════════════════════════════════════
║ ☯️ HeadlessMode? true
╠═════════════════════════════════════════════
2022-06-24 18:37:07.400 23024-23024/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.a.BackgroundGeolocation b]
🔴 Cleared callbacks
2022-06-24 18:37:07.412 23024-23799/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.l.TSLocationManager clearLastOdometerLocation]
ℹ️ Clear last odometer location
2022-06-24 18:37:07.413 23024-23859/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.g.TSGeofenceManager d] ℹ️ Persist monitored geofences: []
2022-06-24 18:37:07.415 23024-23859/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.g.TSGeofenceManager f]
🔴 Stop monitoring geofences
2022-06-24 18:37:07.417 23024-23799/it.vidiemme.brembo.oneapp.dev I/TSLocationManager: [c.t.l.s.ActivityRecognitionService stop]
🔴 Stop motion-activity updates
2022-06-24 18:37:07.418 23024-23799/it.vidiemme.brembo.oneapp.dev I/TSLocationManager: [c.t.l.service.HeartbeatService stop]
🔴 Stop heartbeat
2022-06-24 18:37:07.421 23024-23799/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.http.HttpService stopMonitoringConnectivityChanges]
🔴 Stop monitoring connectivity changes
2022-06-24 18:37:07.422 23024-23799/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.device.DeviceSettings stopMonitoringPowerSaveChanges]
🔴 Stop monitoring powersave changes
2022-06-24 18:37:07.426 23024-23799/it.vidiemme.brembo.oneapp.dev I/TSLocationManager: [c.t.l.p.TSProviderManager stopMonitoring]
🔴 Stop monitoring location-provider changes
2022-06-24 18:37:07.426 23024-23799/it.vidiemme.brembo.oneapp.dev I/TSLocationManager: [c.t.l.s.TSScheduleManager stop]
🔴 Scheduler OFF
2022-06-24 18:37:07.427 23024-23799/it.vidiemme.brembo.oneapp.dev I/TSLocationManager: [c.t.l.a.BackgroundGeolocation$l0 run]
╔═════════════════════════════════════════════
║ MainActivity was destroyed
╠═════════════════════════════════════════════
╟─ stopOnTerminate: true
╟─ enabled: false
2022-06-24 18:37:07.434 23024-23024/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.a.TSLocationManagerActivity onDestroy]
2022-06-24 18:37:07.459 23024-23024/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.service.AbstractService finish] ⚙️︎ finish LocationRequestService [eventCount: 0, sticky: false]
2022-06-24 18:37:07.463 23024-23024/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.service.AbstractService onDestroy]
🔴 LocationRequestService stopped
2022-06-24 18:37:08.104 23024-23024/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.l.LifecycleManager onPause] ☯️ onPause
2022-06-24 18:37:08.106 23024-23024/it.vidiemme.brembo.oneapp.dev D/TSLocationManager: [c.t.l.l.LifecycleManager onStop] ☯️ onStop
Your logs do not show any “crash”.
- Your logs show the MainActivity was destroyed.
- You told the plugin to
stopOnTerminate: true. - The plugin did exactly that: it stopped on terminate.
The problem is not about the plugin stops. The problem is the plugin (in the given scenario) causes the activity to crash. If I disable the "display over other apps" in the device settings then the app behaves correctly and continues its execution without crashing. Basically the app must not crash if I start monitoring when the app is in background and the "display over other apps" is enabled.
Where is the crash? There is no crash in your logs.
the plugin is not involved with the lifecycle of your App’s MainActivity,
This is the strange part. It seems the OS closes the activity, because the app is not listed in recents screen anymore. I can even reproduce in your demo. I don't know why the activity is destroyed, but the behavior occurs only when I try to start monitoring and the app is in background and the "display over other apps" is granted.
We maybe running into this as well when a user is using google maps in Picture in Picture over our app. We're working on getting more details from user reports now.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and I will leave this open.