I have an activity Called 'Signature' and i call it from CordovaPlugin;
Plugin.java
public boolean execute(String action, JSONArray args,
CallbackContext callbackContext) throws JSONException
{
Intent i = new Intent(context, Signature.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
cordova.startActivityForResult(this,i,90);
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
Log.d(TAG, "activity result in plugin: requestCode(" + requestCode + "), resultCode(" + resultCode + ")");
if(requestCode == 90) {
if (resultCode == this.cordova.getActivity().RESULT_OK) {
Bundle res = intent.getExtras();
String result = res.getString("results");
Log.d("FIRST", "result:"+result);
this.callbackContext
.success(result.toString());
} else {
this.callbackContext.error("Error");
}
}
Signature.java
private void finishWithResult(String result,int status)
{
Bundle conData = new Bundle();
conData.putString("results", result);
Intent intent = new Intent();
intent.putExtras(conData);
setResult(status, intent);
finish();
}
However when i call "cordova.startActivityForResult" function "onActivityResult" immediately invokes it self. I cannot callback from Activity via finishWithResult. Any advices. Thanks
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:
Have an example here(for your plugin class) and here(for your signature class).
And one of mine: here and here.