React-native-background-geolocation: App crash on terminate when add headless js

Created on 18 May 2017  ยท  17Comments  ยท  Source: transistorsoft/react-native-background-geolocation

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;
    }
};



md5-3ef98f2ce356f8acd0b5290a4431d452



[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



md5-3fcc01feceeb7928ced806b17f7a06fa




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)

bug

All 17 comments

Thanks, I'll have a look. This new Headless JS feature is very beta. I've not yet had much feedback on it.

I attempted to reproduce your error and could not. Then I looked closely at your code.

Obviously you cannot registerHeadlessTask with a reference you define after. You need to define the reference BackgroundGeolocationService before you use it.

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;
    }
};

You need to do it like this:


// First define your Service:
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;
    }
};

// Now you can use BackgroundGeolocationService
AppRegistry.registerHeadlessTask('BackgroundGeolocation', () => BackgroundGeolocationService);

Hi @christocracy
I have BackgroundGeolocationHeadlessService.js

module.exports = async (event) => {
 console.log('[js] BackgroundGeolocationHeadlessService: ', event.name, event.params);
}

On index.android.js

import { AppRegistry } from 'react-native';
import BackgroundGeolocationHeadlessService from "./BackgroundGeolocationHeadlessService"

AppRegistry.registerHeadlessTask('BackgroundGeolocation', () => BackgroundGeolocationHeadlessService);

On AndroidManifest.xml

<receiver android:name="com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationEventReceiver">
        <intent-filter>
            <!-- You may choose to listen to any, all or none of the following events.  If you don't wish to listen to a particular event, remove it from your AndroidManifest -->
            <action android:name="com.transistorsoft.locationmanager.event.BOOT" />
            <action android:name="com.transistorsoft.locationmanager.event.TERMINATE" />
            <action android:name="com.transistorsoft.locationmanager.event.HEARTBEAT" />
            <action android:name="com.transistorsoft.locationmanager.event.MOTIONCHANGE" />
            <action android:name="com.transistorsoft.locationmanager.event.LOCATION" />
            <action android:name="com.transistorsoft.locationmanager.event.GEOFENCE" />
            <action android:name="com.transistorsoft.locationmanager.event.HTTP" />
            <action android:name="com.transistorsoft.locationmanager.event.SCHEDULE" />
            <action android:name="com.transistorsoft.locationmanager.event.ACTIVITYCHANGE" />
            <action android:name="com.transistorsoft.locationmanager.event.PROVIDERCHANGE" />
            <action android:name="com.transistorsoft.locationmanager.event.GEOFENCESCHANGE" />
        </intent-filter>
     </receiver>

At Home.js

import BackgroundGeolocation from "react-native-background-geolocation";
componentDidMount = () => {
    let geoConfig = {
            // Geolocation Config
            desiredAccuracy: 0,    // Specify the desired-accuracy of the geolocation system with 1 of 4 values, 0, 10, 100, 1000
                                    // where 0 means HIGHEST POWER, HIGHEST ACCURACY and 1000 means LOWEST POWER, LOWEST ACCURACY
            stationaryRadius: 10,
            distanceFilter: 0,      // Must be 0 or locationUpdateInterval is ignored!
            locationUpdateInterval: 3000,
            fastestLocationUpdateInterval: 2000,
            // Activity Recognition
            activityRecognitionInterval: 5000,
            // TODO Must change this value to 1 minutes on production
            stopTimeout: 1,
            minimumActivityRecognitionConfidence: 20,
            // Application config
            debug: false, // <-- 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.
        };

        BackgroundGeolocation.configure(geoConfig, function(state) {
            console.log("- BackgroundGeolocation is configured and ready: ", state.enabled);

            if (!state.enabled) {
                BackgroundGeolocation.start(function() {
                    console.log("- Start success");
                });
            }
        });
  };

When I press back to close my app. The headless js work well
But whenever I press recent button then close all recent apps. App crash with log

05-29 21:25:57.831 23660-23660/com.todolist I/TSLocationManager: โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
                                                                 โ•‘ License Validation Failure
                                                                 โ• โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
                                                                 โ•Ÿโ”€ BackgroundGeolocation is running in evaluation mode.
05-29 21:25:57.851 23660-23660/com.todolist I/TSLocationManager: [c.t.l.a.BackgroundGeolocation <init>] 
                                                                 โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
                                                                 โ•‘ BackgroundGeolocation adapter
                                                                 โ• โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
05-29 21:25:57.871 23660-23660/com.todolist D/TSLocationManager: [c.t.l.d.s.SQLiteLocationDAO dbh] 
                                                                   โœ…  Opened database
05-29 21:25:57.881 23660-23660/com.todolist D/TSLocationManager: [c.t.l.d.s.SQLiteLocationDAO prune] 
                                                                   โ„น๏ธ  PRUNE -1 days
05-29 21:25:57.911 23660-23660/com.todolist D/TSLocationManager: [c.t.l.data.sqlite.GeofenceDAO dbh] 
                                                                   โœ…  Opened database
05-29 21:25:57.931 23660-23660/com.todolist I/TSLocationManager: [c.t.l.a.BackgroundGeolocation <init>] 
                                                                   ๐Ÿ”ต  Connecting to GooglePlayServices...
05-29 21:25:57.941 23660-23660/com.todolist I/TSLocationManager: [c.t.l.BackgroundGeolocationService onStartCommand] 
                                                                 โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
                                                                 โ•‘ BackgroundGeolocation Service started
                                                                 โ• โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
05-29 21:25:57.951 23660-23660/com.todolist I/TSLocationManager: [c.t.l.BackgroundGeolocationService onStartCommand] 
                                                                   โ„น๏ธ  BackgroundGeolocationService waiting for GoogleApiClient to connect
05-29 21:25:57.981 23660-23660/com.todolist D/SecWifiDisplayUtil: Metadata value : SecSettings2
05-29 21:25:57.991 23660-23660/com.todolist D/ViewRootImpl: #1 mView = android.widget.LinearLayout{df9601 V.E...... ......I. 0,0-0,0 #10203a4 android:id/toast_layout_root}
05-29 21:25:57.991 23660-23692/com.todolist D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
05-29 21:25:58.021 23660-23692/com.todolist D/libEGL: eglInitialize EGLDisplay = 0xdf5eb7c4
05-29 21:25:58.021 23660-23692/com.todolist I/OpenGLRenderer: Initialized EGL, version 1.4
05-29 21:25:58.021 23660-23692/com.todolist D/mali_winsys: new_window_surface returns 0x3000,  [637x89]-format:1
05-29 21:25:58.031 23660-23660/com.todolist I/TSLocationManager: [c.t.l.a.BackgroundGeolocation onConnected] 
                                                                   โœ…  Google Play Services: connected (version code:10260000)
05-29 21:25:58.041 23660-23660/com.todolist I/TSLocationManager: [c.t.l.BackgroundGeolocationService onGooglePlayServicesConnected] 
                                                                   ๐Ÿ”ต  BackgroundGeolocation service receives play-services connect event
05-29 21:25:58.051 23660-23660/com.todolist I/TSLocationManager: [c.t.l.a.BackgroundGeolocation requestActivityUpdates] 
                                                                   ๐ŸŽพ  Start activity updates: 5000
05-29 21:25:58.061 23660-23660/com.todolist I/TSLocationManager: [c.t.l.BackgroundGeolocationService a] 
                                                                   ๐Ÿ”ต  setPace: null โ†’ true
05-29 21:25:58.071 23660-23660/com.todolist I/TSLocationManager: [c.t.l.BackgroundGeolocationService i] 
                                                                   ๐Ÿ”ด  Stop heartbeat
05-29 21:25:58.101 23660-23660/com.todolist D/EventBus: No subscribers registered for event class com.transistorsoft.locationmanager.event.StartedEvent
05-29 21:25:58.101 23660-23660/com.todolist D/EventBus: No subscribers registered for event class org.greenrobot.eventbus.NoSubscriberEvent
05-29 21:25:58.101 23660-23660/com.todolist D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
05-29 21:25:58.101 23660-23692/com.todolist D/libGLESv1: DTS_GLAPI : DTS is not allowed for Package : com.todolist
05-29 21:25:58.461 23660-23660/com.todolist D/RelationGraph: garbageCollect()
05-29 21:25:58.481 23660-23717/com.todolist D/TSLocationManager: [c.t.l.LocationService onLocation] 
                                                                 โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
                                                                 โ•‘ LocationService: location:1001
                                                                 โ• โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
                                                                 โ•Ÿโ”€ ๐Ÿ“  Location[fused 10.824782,106.610891 acc=14 et=+14d0h0m57s288ms alt=14.800000190734863 vel=0.0]
05-29 21:25:58.491 23660-23717/com.todolist I/TSLocationManager: [c.t.l.l.TSLocationManager onSingleLocationResult] 
                                                                   ๐Ÿ”ต  Acquired motionchange position
05-29 21:25:58.511 23660-23717/com.todolist D/TSLocationManager: [c.t.l.l.TSLocationManager calculateMedianAccuracy] 14.5
05-29 21:25:58.551 23660-23717/com.todolist D/TSLocationManager: [c.t.l.l.TSLocationManager incrementOdometer] 106.96711
05-29 21:25:58.611 23660-23717/com.todolist I/TSLocationManager: [c.t.l.l.TSLocationManager requestLocationUpdates] 
                                                                   ๐ŸŽพ  Location-services: ON
05-29 21:25:58.621 23660-23660/com.todolist D/RelationGraph: garbageCollect()
05-29 21:25:58.631 23660-23719/com.todolist D/TSLocationManager: [c.t.l.BackgroundGeolocationService onActivityRecognitionResult] still (100%)
05-29 21:25:58.641 23660-23660/com.todolist D/TSLocationManager: [c.t.l.a.BackgroundGeolocation isMainActivityActive] NO
05-29 21:25:58.641 23660-23719/com.todolist D/TSLocationManager: [c.t.l.a.BackgroundGeolocation isMainActivityActive] NO
05-29 21:25:58.661 23660-23720/com.todolist I/TSLocationManager: [c.t.l.d.s.SQLiteLocationDAO persist] 
                                                                   โœ…  INSERT: a661fde4-5943-4c11-b176-8b6e0d665a4e
05-29 21:25:58.661 23660-23719/com.todolist I/TSLocationManager: [c.t.l.BackgroundGeolocationService onActivityRecognitionResult] 
                                                                   ๐Ÿ”ต  Stop-timeout timer initiated (1 min)...
05-29 21:25:58.681 23660-23717/com.todolist D/TSLocationManager: [c.t.l.LocationService onLocation] 
                                                                 โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
                                                                 โ•‘ LocationService: location
                                                                 โ• โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
                                                                 โ•Ÿโ”€ ๐Ÿ“  Location[fused 10.824782,106.610891 acc=14 et=+14d0h0m57s288ms alt=14.800000190734863 vel=0.0]
05-29 21:25:58.691 23660-23719/com.todolist I/TSLocationManager: [c.t.l.BackgroundGeolocationService f] 
                                                                   ๐Ÿ”ต  Begin stop timer
05-29 21:25:58.701 23660-23660/com.todolist I/art: Thread[1,tid=23660,Native,Thread*=0xf5136500,peer=0x75dcb598,"main"] recursive attempt to load library "/data/app/com.todolist-2/lib/arm/libfb.so"
05-29 21:25:58.701 23660-23717/com.todolist D/TSLocationManager: [c.t.l.l.TSLocationManager onLocationResult] 
                                                                 โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
                                                                 โ•‘ Process LocationResult
                                                                 โ• โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
05-29 21:25:58.701 23660-23660/com.todolist D/AndroidRuntime: Shutting down VM
05-29 21:25:58.701 23660-23660/com.todolist E/AndroidRuntime: FATAL EXCEPTION: main
                                                              Process: com.todolist, PID: 23660
                                                              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)

This is the repo to my project
https://github.com/r0b0t3d/react-native-todos branch geo-loc
Please help!
Thanks!

I will attempt to reproduce this.

I'm able to reproduce this by rebooting my device with startOnBoot: true.

Since the react-native app has never booted, there's never been an opportunity to registerHeadlessTask, ie:

AppRegistry.registerHeadlessTask('BackgroundGeolocation', () => BackgroundGeolocationService);

In RBBackgroundGeolocationEventReceiver, I can swallow these errors like so:

@Override
    public void onReceive(Context context, Intent intent) {
        String eventName = getEventName(intent.getAction());

        // Ensure we can reference ReactApplication.  If not, the ReactApplication has not yet been booted so cannot possibly have registered a HeadlessTask.
        try {
            ReactApplication reactApplication = ((ReactApplication) getApplication());
        } catch (AssertionError e) {
            TSLog.logger.warn(TSLog.warn("Failed to fetch ReactApplication.  Task ignored."));
            return;  // <-- Do nothing.  Just return
        }

Hi @christocracy,
I always get this warning

Failed to fetch ReactApplication.  Task ignored.

The purpose that I would like to use headless js is handling location on background. So now if I terminate app (swipe out from recent apps), I could not do anything.

I do not have a problem at all when terminating the app. The headless runs correctly...headless as it were.

Must be related to your device / os. What is your device / os.

Hi @christocracy
This is the information

  • 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

I create a simple app that use react-native-background-geolocation on https://github.com/r0b0t3d/react-native-todos branch geo-loc
You could check it out.

Yea, sorry. I saw that just now in the description.

Where in your "todos" app are you executing:

AppRegistry.registerHeadlessTask('BackgroundGeolocation', () => BackgroundGeolocationService);

?

On index.android.js
```
import { AppRegistry } from 'react-native';
import BackgroundGeolocationHeadlessService from "./BackgroundGeolocationHeadlessService"

AppRegistry.registerHeadlessTask('BackgroundGeolocation', () => BackgroundGeolocationHeadlessService);

ah, shit. you told me that too ;)

Ok, I see what's going on. In order to use Headless JS, you'll have to configure the plugin with foregroundService: true so the service doesn't terminate when you terminate the app.

When using stopOnTerminate: false without foregroundService: true, the background-geolocation service does get terminated when you terminate the app but the OS immediately reschedules it for restart. However, by that time, all references to the ReactApplication have been released.

You must use foregroundService: true in order to use Headless JS.

btw, you should be using the private repo react-native-background-geolocation-android. This is the Free repo for non-customers.

Thanks, @christocracy ,
I will give it a try!

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:

Thanks, @christocracy https://github.com/christocracy ,
I will give it a try!

โ€”
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/transistorsoft/react-native-background-geolocation/issues/255#issuecomment-304756289,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAA6l2_PQNxaaPt8FzyI62fpKqW9kyUlks5r-3ddgaJpZM4NfWhR
.

>

Snet form Gmail Mobile

Was this page helpful?
0 / 5 - 0 ratings

Related issues

leighquince picture leighquince  ยท  3Comments

tofoli picture tofoli  ยท  5Comments

Moveonit picture Moveonit  ยท  5Comments

randymuhroji picture randymuhroji  ยท  3Comments

JAStanton picture JAStanton  ยท  3Comments