Skip to content

Commit 7953707

Browse files
oriharelfacebook-github-bot
authored andcommitted
re #15915 HeadlessJsTaskService is expected to run on UI thread
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
1 parent df8d0d1 commit 7953707

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

ReactAndroid/src/main/java/com/facebook/react/HeadlessJsTaskService.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,19 @@ public void onReactContextInitialized(ReactContext reactContext) {
116116
}
117117
}
118118

119-
private void invokeStartTask(ReactContext reactContext, HeadlessJsTaskConfig taskConfig) {
120-
HeadlessJsTaskContext headlessJsTaskContext = HeadlessJsTaskContext.getInstance(reactContext);
119+
private void invokeStartTask(ReactContext reactContext, final HeadlessJsTaskConfig taskConfig) {
120+
final HeadlessJsTaskContext headlessJsTaskContext = HeadlessJsTaskContext.getInstance(reactContext);
121121
headlessJsTaskContext.addTaskEventListener(this);
122-
int taskId = headlessJsTaskContext.startTask(taskConfig);
123-
mActiveTasks.add(taskId);
122+
123+
UiThreadUtil.runOnUiThread(
124+
new Runnable() {
125+
@Override
126+
public void run() {
127+
int taskId = headlessJsTaskContext.startTask(taskConfig);
128+
mActiveTasks.add(taskId);
129+
}
130+
}
131+
);
124132
}
125133

126134
@Override

0 commit comments

Comments
 (0)