1

I'm trying to initiate an SDK module that is built in Java using React Native. In this case, I have to bridge the module using the "ReactContextBaseJavaModule" library.

Unfortunately, the module needed a context to initiate the SDK, so the class needed to initiate it, needed to be AppCompatActivity.

In this case, I create two classes: one react bridge class module and one just for SDK functions. I tried to import the SDK class extending AppCompatActivity into the react module class extending ReactContextBaseJavaModule, but I keep getting this looping error:

Can't create handler inside thread Thread[create_react{context,5,main] that has not called Looper.prepare();

Here is my code:

ReactModule.java


public class ReactModule extends ReactContextBaseJavaModule {

    private static ReactApplicationContext reactContext;

    ReactModule(ReactApplicationContext context) {
        super(context);
        reactContext = context;
    }

    @NonNull
    @Override
    public String getName() {
        return "ReactModule";
    }

    // ------ where big boy code starts

    SDKModule wrappedReactModule = new SDKModule();

    @ReactMethod
    public void initiateSdk() {
        wrappedReactModule.initiateSdk();
    }

}

SDKModule.java

public class SDKModule extends AppCompatActivity {
    

    public Sdk SdkMod = new Sdk(this); //context part, which is "this", needed it

    public void initiateSdk() {
        // some other stuff in here
    }
}

I'm not that experienced with Java, so no idea what this means with Looper. Any help or guidance is appreciated!

frankied003
  • 466
  • 6
  • 26
  • My guess is that somewhere you're calling a handler to update the UI in the Android app. In Android, you can only update your UI elements from the main thread (also called UI thread). I think this post might help you: https://stackoverflow.com/questions/6213538/cant-create-handler-inside-thread-that-has-not-called-looper-prepare – Jorn Rigter Mar 04 '22 at 10:12

0 Answers0