title: No task registered for key error while using headless JS
body: <p>I am using foreground service for detecting beacons since Android Oreo kills all background services, we decided to go on with foreground service to detect beacons when the app is in foreground/killed/in background.</p>
  
  <p>This works fine on android 7.0 and below but on android 8 it throws an error "No task registered for key "didEnterRegion"</p>
  
  <p>This is my code
  Helper.java</p>
  
  <pre><code>public static void sendNewBeacons(Context context, Collection&lt;Beacon&gt; beacons) {
      if (beacons != null &amp;&amp; beacons.size() &gt; 0) {
          for (Beacon beacon : beacons) {
              Intent service = new Intent(context, MyTaskService.class);
              service.putExtra("eventName", "didEnterRegion");
              service.putExtra("beacon", (Parcelable) beacon);
              context.startService(service);
              HeadlessJsTaskService.acquireWakeLockNow(context);
          }
      }
  }
  
  public static void sendRemovedBeacons(Context context, Collection&lt;Beacon&gt; beacons) {
      if (beacons != null &amp;&amp; beacons.size() &gt; 0) {
          for (Beacon beacon : beacons) {
              Intent service = new Intent(context, MyTaskService.class);
              service.putExtra("eventName", "didExitRegion");
              service.putExtra("beacon", (Parcelable) beacon);
              context.startService(service);
              HeadlessJsTaskService.acquireWakeLockNow(context);
          }
      }
  }
  </code></pre>
  
  <p>This is TaskService code</p>
  
  <pre><code>public class MyTaskService extends HeadlessJsTaskService {
  private final String TAG = "TaskService";
  
  
  @Override
  protected @Nullable
  HeadlessJsTaskConfig getTaskConfig(Intent intent) {
  Bundle extras = intent.getExtras();
  if (extras == null) {
      return null;
  }
  
  String event = extras.getString("eventName");
  if (TextUtils.isEmpty(event)) {
    return null;
  }
  
  WritableMap map = new WritableNativeMap();
  if (extras.containsKey("beacon")) {
    map = BeaconHelper.getObject((Beacon) 
  extras.getParcelable("beacon"));
  }
  
  Log.d(TAG, event);
  return new HeadlessJsTaskConfig(event, map,5000, true);
  
  }
  
  @Override
  public void onHeadlessJsTaskFinish(int taskId) {
  super.onHeadlessJsTaskFinish(taskId);
  }
  </code></pre>
  
  <p>This is my App.js</p>
  
  <pre><code>AppRegistry.registerHeadlessTask('didEnterRegion', () =&gt;
      require('./BeaconEntering.js'));
  AppRegistry.registerHeadlessTask('didExitRegion', () =&gt; 
      require('./BeaconExiting.js'));
  
  const myModuleEvt = new 
      NativeEventEmitter(NativeModules.BeaconManager);
  const rangeBeacon = myModuleEvt.addListener('didRangeBeacons', 
      Util.didRangeBeacons);
  
  const exitRegion = myModuleEvt.addListener('didExitRegion', 
      Util.didExitRegion);
  
  const entryRegion = 
      myModuleEvt.addListener('didEnterRegion',Util.didEnterRegion);
  </code></pre>
  
  <p>This is a log before crash</p>
  
  <p>09-12 20:03:25.801 15850-22489/com.kr_beaconmanager D/BluetoothAdapter: isLeEnabled(): ON</p>
  
  <p>09-12 20:03:25.802 15850-15850/com.kr_beaconmanager I/ScanJob: We are inside a beacon region.  We will not scan between cycles.</p>
  
  <p>09-12 20:03:25.809 15850-15850/com.kr_beaconmanager I/System.out: null checkBeacons [id1: 341e458b-ad9e-4981-b01f-ddbce8f43d5c id2: 18 id3: 18]
      handleNewAndRemovedBeacon 1 >&lt; 0</p>
  
  <p>09-12 20:03:25.824 15850-15850/com.kr_beaconmanager I/System.out: showNotification didRangeBeaconsInRegion</p>
  
  <p>09-12 20:03:25.828 15850-15850/com.kr_beaconmanager I/System.out: didEnterRegion</p>
  
  <p>09-12 20:03:25.830 15850-15913/com.kr_beaconmanager E/ReactNativeJS: No task registered for key didEnterRegion</p>
  
  <p>09-12 20:03:26.031 15850-15850/com.kr_beaconmanager I/CycledLeScanner: Using Android O scanner</p>
  
  <p>09-12 20:03:26.033 15850-15850/com.kr_beaconmanager I/ScanJob: Using immediateScanJobId from manifest: 208352939 Running immediate scan job: instance is org.altbeacon.beacon.service.ScanJob@f13f916</p>
  
  <p>09-12 20:03:26.034 15850-15850/com.kr_beaconmanager I/ScanJob: scanJob version 2.15.1 is starting up on the main process</p>
  
  <p>09-12 20:03:26.035 15850-15855/com.kr_beaconmanager I/zygote: Compiler allocated 4MB to compile void android.widget.TextView.(android.content.Context, android.util.AttributeSet, int, int)</p>
  
  <p>09-12 20:03:26.037 15850-15850/com.kr_beaconmanager W/ModelSpecificDistanceCalculator: Cannot find match for this device.  Using default Cannot find match for this device.  Using default</p>
  
  <p><a href="https://i.stack.imgur.com/VqGse.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VqGse.jpg" alt="enter image description here"></a></p>