Callback not firing in Android Native Module
I've written a native module with the method
@ReactMethod
public void getModel(Callback cb) {
try{
String model = Build.MODEL;
cb.invoke(model);
}catch (Exception e){
cb.invoke("err");
}
}
But when I invoke in JS with
MyNativeModule.getModel(function (data) {
console.log(data, "data");
});
I get nothing back. No errors, no logs, nothing. I've tried logging from Java with System.out, but that doesn't log anything.
Any ideas? Thanks in advance!
Any errors you see in debugger?
No errors, just silence
@madwed - are you sure that Build.MODEL is evaluating to anything? If you add a log message inside of getModel does it show it as being called? What if you just change it to cb.invoke("hi there!")? cc @kmagiera
Figured out the issue. I needed to connect the app to the react tab in chrome dev tools. Relying on only the chrome console didn't work. Once I connected the app I started seeing all the logs I was missing.
Thanks for all your help.
@madwed sorry for not getting back to you earlier. Glad to hear the issue has been resolved.