Reputation: 31
import {AppRegistry} from 'react-native';
import App from './App';
import task from './src/task';
import {name as appName} from './app.json';
//AppRegistry.registerComponent('App',()=>App);
AppRegistry.registerHeadlessTask('SomeTaskName', () =>
task
);
package com.convertwebsitetoapp;
import android.content.Intent;
import android.os.Bundle;
import com.facebook.react.HeadlessJsTaskService;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.jstasks.HeadlessJsTaskConfig;
import javax.annotation.Nullable;
public class MyTaskService extends HeadlessJsTaskService {
@Override
protected @Nullable HeadlessJsTaskConfig getTaskConfig(Intent intent) {
Bundle extras = intent.getExtras();
if (extras != null) {
return new HeadlessJsTaskConfig(
"SomeTaskName",
Arguments.fromBundle(extras),
5000, // timeout for the task
false // optional: defines whether or not the task is allowed in foreground. Default is false
);
}
return null;
}
}
task.js
module.exports = async (taskData) => {
console.log('Demo')
};
I am new in React-Native. Trying to create an app using headless js in react-native
When i start MyTask service inside oncreate
method then
the app is crashing and not opening. And when am registering without component registerheadlessjs
task then am getting the error as "registercompoent
was not called"
Please give me one simple example if anyone has.
Thanks in advance
Upvotes: 3
Views: 1843
Reputation: 37
return new HeadlessJsTaskConfig(
"SomeTaskName",
Arguments.fromBundle(extras),
5000, // timeout for the task
true// optional: defines whether or not the task is allowed in foreground. Default is false
);
Change false to true
Upvotes: 0