React Native Headless js, Module AppRegistry is not a registered(calling startHeadlessTask)


#1

I am having react native background service issue - Headless JS(android)

Android Studio Error MSG:

E/ReactNativeJS: The Expo SDK requires Expo to run. It appears the native Expo modules are unavailable and this code is not running on Expo. Visit https://docs.expo.io to learn more about developing an Expo project.
E/unknown:ReactNative: Unable to launch redbox because react activity is not available, here is the error that redbox would've displayed: The Expo SDK requires Expo to run. It appears the native Expo modules are unavailable and this code is not running on Expo. Visit https://docs.expo.io to learn more about developing an Expo project.
E/ReactNativeJS: Module AppRegistry is not a registered callable module (calling startHeadlessTask) 
E/unknown:ReactNative: Unable to launch redbox because react activity is not available, here is the error that redbox would've displayed: Module AppRegistry is not a registered callable module (calling startHeadlessTask)

The JS API:(App.js)

const LockScreenOpenService = async (taskData) => {
   DeviceEventEmitter.addListener('LockScreenOpen', function(e: Event) {
      // handle event.
      console.log("== Debug: Received LockScreen View Open");
   });
};

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

LockScreenOpenService.java:

public class LockScreenOpenService extends HeadlessJsTaskService {

@Override
protected @Nullable
HeadlessJsTaskConfig getTaskConfig(Intent intent) {
    Bundle extras = intent.getExtras();
    if (extras != null) {
        return new HeadlessJsTaskConfig(
                "LockScreenOpenService",
                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;
}
}

Service Start:

public void startLockViewService(){
  Intent listenIntent = new Intent(getApplication(), LockScreenOpenService.class);
  Bundle bundle = new Bundle();

  listenIntent.putExtras(bundle);
  startService(listenIntent);
}

AndroidManifest.xml

 <service
    android:name=".lockscreen.LockScreenOpenService"
    android:enabled="true"
    android:exported="true" />

I have no idea why ‘Module AppRegistry is not a registered callable module (calling startHeadlessTask)’ occured!?


How to Open specific component in android activity?
closed #2

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