Detached ExpoKit and Headless JS

Hi there,

I have been having problems trying to get Headless JS task to execute on a detached ExpoKit project (SDK25). I have used the React Native documentation to do this.

I have a broadcast receiver

public class MessageReceivedReceiver extends BroadcastReceiver {
    private static final String TAG = "MessageReceivedReceiver";
    public void onReceive(Context context, Intent intent) {
        Log.i(TAG, "onReceive");
        if (!isAppOnForeground((context))) {
            Log.i(TAG, "Not in foreground");
             We will start our service and send extra info about
             network connections
            Intent serviceIntent = new Intent(context, JSBackgroundService.class);

A HeadlessJS Task Service:

public class JSBackgroundService extends HeadlessJsTaskService {
    final static String TAG = "JSBackgroundService";
    protected @Nullable
    HeadlessJsTaskConfig getTaskConfig(Intent intent) {
        Bundle extras = intent.getExtras();
        Log.i(TAG, String.format("getTaskConfig: %s", extras));
        if (extras != null) {
            return new HeadlessJsTaskConfig(
                    5000, // timeout for the task
                    false // optional: defines whether or not  the task is allowed in foreground. Default is false
        return null;

My MainApplication implements ReactApplication:

public class MainApplication extends ExpoApplication implements ReactApplication {

private static final String TAG = MainApplication.class.getSimpleName();

private List<ReactPackage> packages = Arrays.<ReactPackage>asList(

// new MainReactPackage(),
new MyReactPackage()

private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    public boolean getUseDeveloperSupport() {
        return BuildConfig.DEBUG;

    protected List<ReactPackage> getPackages() {
        return packages;

public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;

In App.js I have:

import JSBackgroundService from ‘./services/jsbackgroundservice’;
AppRegistry.registerHeadlessTask(‘Test’, () => {console.log(“Got it”); return JSBackgroundService; });

export default class App extends React.Component {

And JsBackgroundService:

module.exports = async (e) => {
    // do stuff
    console.log("Running the background service");

Based on logs I know that getTaskConfig is executed but for some reason, I don’t see anything in the console logs, looks like the javascript never gets executed. I have tried also running the Headless JS in foreground for testing purposes but to no avail.

Does anyone have any ideas what could I be doing wrong?


I have debugged the problem a bit further and it seems that this line of code should get executed but never does. In other words the react context does not get initialized.

Any advices?


This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.