Skip to content

Commit

Permalink
re #15915 HeadlessJsTaskService is expected to run on UI thread
Browse files Browse the repository at this point in the history
Summary:
<!--
Thank you for sending the PR! We appreciate you spending the time to work on these changes.

Help us understand your motivation by explaining why you decided to make this change.

You can learn more about contributing to React Native here: http://facebook.github.io/react-native/docs/contributing.html

Happy contributing!

-->

Headless tasks are required to run in the main thread, however due to the nature of the React context creation flow, the handler may be returned outside of the main thread, causing the HeadlessJsTaskContext to throw an exception.

Swipe out the app. send push notification from a server that starts a HeadlessJsTaskService
Closes #15940

Differential Revision: D5852448

Pulled By: foghina

fbshipit-source-id: 54c58a1eb7434dd5de5c39c28f6e068ed15ead9d
  • Loading branch information
oriharel authored and facebook-github-bot committed Sep 18, 2017
1 parent df8d0d1 commit 7953707
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7953707

Please sign in to comment.