Callback From Activity On Cordova
I have an activity Called 'Signature' and i call it from CordovaPlugin; Plugin.java public boolean execute(String action, JSONArray args, CallbackContext callbackContex
Solution 1:
First of all there was some code missing(return-statement for execute-method) and you have to tell android/cordova-plugin to wait until there is a result sent back to your webview-app by using NO_RESULT and setKeepCallback of PluginResult otherwise cordova/android expects to get an result as soon as execute-method has finished:
Plugin.java:
publicbooleanexecute(String action, JSONArray args,
CallbackContext callbackContext)throws JSONException
{
PluginResultr=newPluginResult(PluginResult.Status.NO_RESULT);
r.setKeepCallback(true);
callbackContext.sendPluginResult(r);
Intenti=newIntent(context, Signature.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
cordova.startActivityForResult(this,i,90);
returntrue;
}
publicvoidonActivityResult(int requestCode, int resultCode, Intent intent){
// here is your former code
...
...
// at last call sendPluginResult this.callbackContext.sendPluginResult(newPluginResult(PluginResult.Status.OK, result.toString()));
// when there is no direct result form your execute-method use sendPluginResult because most plugins I saw and made recently (Reminder) prefer sendPluginResult to success/error// this.callbackContext.success(result.toString());
}
Have an example here(for your plugin class) and here(for your signature class).
Post a Comment for "Callback From Activity On Cordova"