react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Callback not firing in Android Native Module

Open madwed opened this issue 11 years ago • 5 comments

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!

madwed avatar Oct 06 '15 20:10 madwed

Any errors you see in debugger?

satya164 avatar Oct 06 '15 20:10 satya164

No errors, just silence

madwed avatar Oct 06 '15 20:10 madwed

@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

brentvatne avatar Oct 06 '15 22:10 brentvatne

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 avatar Oct 07 '15 13:10 madwed

@madwed sorry for not getting back to you earlier. Glad to hear the issue has been resolved.

kmagiera avatar Oct 07 '15 13:10 kmagiera