react-native-background-geolocation: BootCompletedReceiver does not work (Android)

Module does not work on app termination and phone boot (Android)

Your Environment

  • Plugin version: 0.5.0-alpha.33
  • Platform: Android
  • OS version: 8.0
  • Device manufacturer and model: Sony XA1
  • React Native version: 0.55.2
  • Plugin configuration options:
{
    activitiesInterval: 1000,
    activityType: 'Fitness',
    desiredAccuracy: BackgroundGeolocation.LOW_ACCURACY,
    distanceFilter: 10,
    debug: false,
    fastestInterval: 30000,
    interval: 60000,
    locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER,
    maxLocations: 1000000,
    startForeground: true,
    startOnBoot: true,
    stationaryRadius: 10,
    stopOnTerminate: false,
    stopOnStillActivity: false,
}
  • Link to your project:

Context

Expected Behavior

No errors

Actual Behavior

Possible Fix

Tried to add the following into AndroidManifest.xml, but does not help:

    <service android:name="com.marianhello.bgloc.LocationService"/>
    <receiver android:name="com.marianhello.bgloc.BootCompletedReceiver" android:enabled="true" android:exported="true">
      <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED"/>
        <action android:name="android.intent.action.QUICKBOOT_POWERON"/>
        <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
        <category android:name="android.intent.category.DEFAULT" />
      </intent-filter>
    </receiver>

Debug logs

Logs from Crashalitics:

Fatal Exception: java.lang.RuntimeException
Unable to start receiver com.marianhello.bgloc.BootCompletedReceiver: java.lang.IllegalStateException: Not allowed to start service Intent { flg=0x4 cmp=com.dvaplus.best/com.marianhello.bgloc.LocationService (has extras) }: app is in background uid UidRecord{f611f74 u0a450 RCVR idle procs:1 seq(0,0,0)}
Caused by java.lang.IllegalStateException
Not allowed to start service Intent { flg=0x4 cmp=com.dvaplus.best/com.marianhello.bgloc.LocationService (has extras) }: app is in background uid UidRecord{f611f74 u0a450 RCVR idle procs:1 seq(0,0,0)}
com.marianhello.bgloc.BootCompletedReceiver.onReceive (BootCompletedReceiver.java:51)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 7
  • Comments: 19 (4 by maintainers)

Most upvoted comments

@mauron85 Any ideas why this bug is occurred and how to fix it?

@priezz I’m getting the same error in Crashlytics, did you find out what is causing the problem? and how to fix that bug?

Sorry oreo README section was removed in recent commit. Since 0.6.0 only supports Oreo and later and there is no additional step to take.

I’m seeing this in production on 0.5.0-alpha.50

java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.equesteo/com.marianhello.bgloc.service.LocationServiceImpl (has extras) }: app is in background uid UidRecord{b01fb2a u0a247 CEM  bg:+10h18m42s978ms idle procs:2 seq(0,0,0)}
    at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1577)
    at android.app.ContextImpl.startService(ContextImpl.java:1532)
    at android.content.ContextWrapper.startService(ContextWrapper.java:664)
    at com.marianhello.bgloc.service.LocationServiceProxy.executeIntentCommand(LocationServiceProxy.java:93)
    at com.marianhello.bgloc.service.LocationServiceProxy.stop(LocationServiceProxy.java:58)
    at com.marianhello.bgloc.BackgroundGeolocationFacade.stopBackgroundService(BackgroundGeolocationFacade.java:440)
    at com.marianhello.bgloc.BackgroundGeolocationFacade.destroy(BackgroundGeolocationFacade.java:264)
    at com.marianhello.bgloc.react.BackgroundGeolocationModule.onHostDestroy(BackgroundGeolocationModule.java:125)
    at com.facebook.react.bridge.ReactContext.onHostDestroy(ReactContext.java:228)
    at com.facebook.react.ReactInstanceManager.moveToBeforeCreateLifecycleState(ReactInstanceManager.java:676)
    at com.facebook.react.ReactInstanceManager.onHostDestroy(ReactInstanceManager.java:585)
    at com.facebook.react.ReactInstanceManager.onHostDestroy(ReactInstanceManager.java:599)
    at com.reactnativenavigation.react.NavigationReactInitializer.onActivityDestroyed(NavigationReactInitializer.java:43)
    at com.reactnativenavigation.react.ReactGateway.onActivityDestroyed(ReactGateway.java:64)
    at com.reactnativenavigation.NavigationActivity.onDestroy(NavigationActivity.java:70)
    at android.app.Activity.performDestroy(Activity.java:7403)
    at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1306)
    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4481)
    at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4515)
    at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:39)
    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6718)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

java.lang.RuntimeException: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.equesteo/com.marianhello.bgloc.service.LocationServiceImpl (has extras) }: app is in background uid UidRecord{b01fb2a u0a247 CEM  bg:+10h18m42s978ms idle procs:2 seq(0,0,0)}
    at com.facebook.react.bridge.ReactContext.handleException(ReactContext.java:311)
    at com.facebook.react.bridge.ReactContext.onHostDestroy(ReactContext.java:230)
    at com.facebook.react.ReactInstanceManager.moveToBeforeCreateLifecycleState(ReactInstanceManager.java:676)
    at com.facebook.react.ReactInstanceManager.onHostDestroy(ReactInstanceManager.java:585)
    at com.facebook.react.ReactInstanceManager.onHostDestroy(ReactInstanceManager.java:599)
    at com.reactnativenavigation.react.NavigationReactInitializer.onActivityDestroyed(NavigationReactInitializer.java:43)
    at com.reactnativenavigation.react.ReactGateway.onActivityDestroyed(ReactGateway.java:64)
    at com.reactnativenavigation.NavigationActivity.onDestroy(NavigationActivity.java:70)
    at android.app.Activity.performDestroy(Activity.java:7403)
    at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1306)
    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4481)
    at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4515)
    at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:39)
    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6718)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

java.lang.RuntimeException: Unable to destroy activity {com.equesteo/com.equesteo.MainActivity}: java.lang.RuntimeException: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.equesteo/com.marianhello.bgloc.service.LocationServiceImpl (has extras) }: app is in background uid UidRecord{b01fb2a u0a247 CEM  bg:+10h18m42s978ms idle procs:2 seq(0,0,0)}
    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4496)
    at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4515)
    at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:39)
    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6718)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

I believe this has been already fixed

+1, we’re seeing these crashes happen over and over for live users.

I’m also getting this error, guys. Any update on the cause?