How to implement Headless JS in react native android application?

寵の児 提交于 2019-11-30 14:38:11

You have to register a headless task. So replace the following code:

AppRegistry.registerComponent('SomeTaskName', () => SomeTaskName);

with:

AppRegistry.registerHeadlessTask('SomeTaskName', () => SomeTaskName);

And you need to call the task from your service, so replace:

if (extras != null) {
    return new HeadlessJsTaskConfig(
      "MyTaskService",
      Arguments.fromBundle(extras),
     5000);
 }
 return null;

with:

// Following line just to be sure it does not silently fail
WritableMap data = extras != null ? Arguments.fromBundle(extras) : null;
return new HeadlessJsTaskConfig(
    "SomeTaskName", // Use the registered headless Task here
    data,
    5000);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!