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!