Reputation: 1217
I am developing cordova plugin for the first time and stuck in the following issue.
I have created a class extending CorodvaPlugin and override execute method as given . What I want is after the asynctask has completed it background task, response is returned to the JS and values are displayed on the HTML but whats happening sometimes values are displayed and sometimes not.Any help would be appreciated.
@Override
public boolean execute(String action, JSONArray args,
CallbackContext callbackContext) throws JSONException {
try {
context = this.cordova.getActivity().getApplicationContext();
this.mMyCallbackContext = callbackContext;
new WSCall().execute();
PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
pluginResult.setKeepCallback(true);
mMyCallbackContext .sendPluginResult(pluginResult);
return true;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
}
and in the Async Task post execute I have done this
@Override
protected void onPostExecute(String result) {
PluginResult result_;
if(groups!=null)
result_ = new PluginResult(PluginResult.Status.OK, groups);
else if(ret_msg!=null)
result_ = new PluginResult(PluginResult.Status.OK, ret_msg);
else
result_ = new PluginResult(PluginResult.Status.OK, "");
result_.setKeepCallback(false);
mMyCallbackContext.sendPluginResult(result_);
pDialog.dismiss();
}
Upvotes: 2
Views: 2443
Reputation: 479
Use this link and don't return true from execute method ,return Pluginresult only.
Upvotes: 1