diff --git a/ReactAndroid/src/main/java/com/facebook/react/HeadlessJsTaskService.java b/ReactAndroid/src/main/java/com/facebook/react/HeadlessJsTaskService.java index 4d88f009c29ea9..3add544a9fd78f 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/HeadlessJsTaskService.java +++ b/ReactAndroid/src/main/java/com/facebook/react/HeadlessJsTaskService.java @@ -116,11 +116,19 @@ public void onReactContextInitialized(ReactContext reactContext) { } } - private void invokeStartTask(ReactContext reactContext, HeadlessJsTaskConfig taskConfig) { - HeadlessJsTaskContext headlessJsTaskContext = HeadlessJsTaskContext.getInstance(reactContext); + private void invokeStartTask(ReactContext reactContext, final HeadlessJsTaskConfig taskConfig) { + final HeadlessJsTaskContext headlessJsTaskContext = HeadlessJsTaskContext.getInstance(reactContext); headlessJsTaskContext.addTaskEventListener(this); - int taskId = headlessJsTaskContext.startTask(taskConfig); - mActiveTasks.add(taskId); + + UiThreadUtil.runOnUiThread( + new Runnable() { + @Override + public void run() { + int taskId = headlessJsTaskContext.startTask(taskConfig); + mActiveTasks.add(taskId); + } + } + ); } @Override