Reputation: 1355
I need to return a value from JSNI GWT method like so:
public native int connect(String macAdress) /*-{
var result = 0;
$wnd.bluetoothSerial.connect(macAdress, function() {
$wnd.console.log("connect success");
result = 1 ;
}, function() {
$wnd.console.log("Failed connect");
});
return result;
}-*/;
form some reasons it return 0 even if the connection successful. Apparently this variable keep the default value, Any ideas?
Upvotes: 0
Views: 392
Reputation: 16060
You are calling an asychronous method and can't return a value that way.
You will need to pass an Callback into your native code:
See Pass Java Callback Function to JSNI Method?
Upvotes: 3