react-native-background-geolocation: App crash on terminate when add headless js
Your Environment
- Plugin version: 2.8.1
- Platform: Android
- OS version: 6.0.1
- Device manufacturer / model: Samsung Tab A 10.1
- React Native version (
react-native -v
): 0.41.2 - Plugin config
BackgroundGeolocation.on('location', (location) => {
console.log("BGLocation", location);
});
BackgroundGeolocation.configure({
// Geolocation Config
desiredAccuracy: 20,
stationaryRadius: 10,
distanceFilter: 0,
// TODO Must change this value to 1 minutes on production
// Activity Recognition
stopTimeout: 15,
// Application config
debug: true, // <-- enable this hear sounds for background-geolocation life-cycle.
logLevel: BackgroundGeolocation.LOG_LEVEL_DEBUG,
stopOnTerminate: false, // <-- Allow the background-service to continue tracking when user closes the app.
startOnBoot: true, // <-- Auto start tracking when device is powered-up.
// HTTP / SQLite config
url: 'http://yourserver.com/locations',
batchSync: false, // <-- [Default: false] Set true to sync locations to server in a single HTTP request.
autoSync: false, // <-- [Default: true] Set true to sync each location to server as it arrives.
}, function(state) {
console.log("- BackgroundGeolocation is configured and ready: ", state.enabled);
if (!state.enabled) {
BackgroundGeolocation.start(function() {
console.log("- Start success");
});
}
});
BackgroundGeolocation.changePace(true);
AppRegistry.registerHeadlessTask('BackgroundGeolocation', () => BackgroundGeolocationService);
const BackgroundGeolocationService = async (event) => {
// do stuff
console.log('[js] BackgroundGeolocationService: ', event);
switch (event.name) {
case 'boot':
break;
case 'terminate':
break;
case 'heartbeat':
break;
case 'motionchange':
break;
case 'location':
break;
case 'geofence':
break;
case 'http':
break;
case 'schedule':
break;
case 'activitychange':
break;
case 'providerchange':
break;
case 'geofenceschange':
break;
}
};
Expected Behavior
App can update location on background
Actual Behavior
App crash
Steps to Reproduce
- Start app with the config above
- Location updates normally
- Press recent button then swipe out app to terminate
- App crash
Context
I’m trying to get location update when app is terminated.
Debug logs
This is the logs when I terminate the app
[c.t.l.a.BackgroundGeolocation onActivityDestroy]
╔═════════════════════════════════════════════
║ MainActivity was destroyed
╠═════════════════════════════════════════════
╟─ stopOnTerminate: false
╟─ enabled: true
05-18 21:46:21.265 26957-26957/com.drivebuddy I/TSLocationManager: [c.t.l.l.TSLocationManager stopWatchPosition]
🔴 watchPosition: OFF
05-18 21:46:21.275 26957-26957/com.drivebuddy D/TSLocationManager: [c.t.l.a.BackgroundGeolocation f]
🔴 Cleared callbacks
05-18 21:46:21.285 26957-26957/com.drivebuddy I/TSLocationManager: [c.t.l.a.BackgroundGeolocation removeActivityUpdates]
🔴 Stop activity updates
05-18 21:46:21.305 26957-26957/com.drivebuddy D/TSLocationManager: [c.t.l.BackgroundGeolocationService onActivityDestroyed]
╔═════════════════════════════════════════════
║ BackgroundGeolocationService Rx ActivityDestroyed
╠═════════════════════════════════════════════
05-18 21:46:21.315 26957-26957/com.drivebuddy D/TSLocationManager: [c.t.l.BackgroundGeolocationService g]
05-18 21:46:21.335 26957-26957/com.drivebuddy I/TSLocationManager: [c.t.l.BackgroundGeolocationService i]
🔴 Stop heartbeat
05-18 21:46:21.355 26957-26957/com.drivebuddy D/TSLocationManager: [c.t.l.a.BackgroundGeolocation isMainActivityActive] NO
05-18 21:46:21.375 26957-26957/com.drivebuddy D/TSLocationManager: [c.t.r.RNBackgroundGeolocationEventReceiver onHeadlessJsTaskStart] onHeadlessJsTaskStart: 1
05-18 21:46:21.415 26957-26957/com.drivebuddy D/TSLocationManager: [c.t.r.RNBackgroundGeolocationEventReceiver onHeadlessJsTaskFinish] onHeadlessJsTaskFinish: 1
After then, it showed this exception
05-18 21:46:30.235 27671-27738/com.drivebuddy D/TSLocationManager: [c.t.l.LocationService onLocation]
╔═════════════════════════════════════════════
║ LocationService: location:1001
╠═════════════════════════════════════════════
╟─ 📍 Location[fused 10.824846,106.611039 acc=10 et=+3d0h21m23s757ms alt=-1.899999976158142 vel=0.0]
05-18 21:46:30.255 27671-27738/com.drivebuddy I/TSLocationManager: [c.t.l.l.TSLocationManager onSingleLocationResult]
🔵 Acquired motionchange position
05-18 21:46:30.265 27671-27738/com.drivebuddy D/TSLocationManager: [c.t.l.l.TSLocationManager calculateMedianAccuracy] 10.0
05-18 21:46:30.275 27671-27738/com.drivebuddy D/TSLocationManager: [c.t.l.l.TSLocationManager incrementOdometer] 30402.67
05-18 21:46:30.305 27671-27738/com.drivebuddy I/TSLocationManager: [c.t.l.l.TSLocationManager requestLocationUpdates]
🎾 Location-services: ON
05-18 21:46:30.355 27671-27740/com.drivebuddy I/TSLocationManager: [c.t.l.d.s.SQLiteLocationDAO persist]
✅ INSERT: c110816d-ea8e-45e4-a173-c64f8086516e
05-18 21:46:30.365 27671-27671/com.drivebuddy D/TSLocationManager: [c.t.l.a.BackgroundGeolocation isMainActivityActive] NO
05-18 21:46:30.375 27671-27738/com.drivebuddy I/TSLocationManager: [c.t.l.LocationService onLocation]
ℹ️ Location availability: true
05-18 21:46:30.425 27671-27671/com.drivebuddy I/art: Thread[1,tid=27671,Native,Thread*=0xf5136500,peer=0x75dcb598,"main"] recursive attempt to load library "/data/app/com.drivebuddy-2/lib/arm/libfb.so"
05-18 21:46:30.425 27671-27671/com.drivebuddy D/AndroidRuntime: Shutting down VM
05-18 21:46:30.425 27671-27671/com.drivebuddy E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.drivebuddy, PID: 27671
java.lang.AssertionError
at com.facebook.infer.annotation.Assertions.assertNotNull(Assertions.java:21)
at com.facebook.react.common.ApplicationHolder.getApplication(ApplicationHolder.java:35)
at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationEventReceiver.getReactNativeHost(RNBackgroundGeolocationEventReceiver.java:95)
at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationEventReceiver.startTask(RNBackgroundGeolocationEventReceiver.java:179)
at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationEventReceiver.onReceive(RNBackgroundGeolocationEventReceiver.java:149)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3686)
at android.app.ActivityThread.access$2000(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1903)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7303)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 17 (11 by maintainers)
foregroundService: true makes the plugin’s service far more robust, more immune to os termination when under memory pressure.
It is the most desirable mode of operation.
On Mon, May 29, 2017 at 9:56 PM Tuan Luong notifications@github.com wrote:
– Snet form Gmail Mobile
I will attempt to reproduce this.