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 https://github.com/facebook/react-native/pull/15940 Differential Revision: D5852448 Pulled By: foghina fbshipit-source-id: 54c58a1eb7434dd5de5c39c28f6e068ed15ead9d
This commit is contained in:
parent
df8d0d1db9
commit
795370789b
|
@ -116,11 +116,19 @@ public abstract class HeadlessJsTaskService extends Service implements HeadlessJ
|
|||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue