Acquire returned value from PhoneGap Plugin

thewhite_die

New Member
I built a very simple PhoneGap Plugin to start testing the way I'm going to build some native actions on Android.JavaScript: function callNativePlugin() { cordova.exec(nativePluginResultHandler, nativePluginErrorHandler, "Database", "saveAdvertencia", [ 1, "TesteAdv" ]); }\[code\] function nativePluginResultHandler(result) { alert("SUCCESS: \r\n" + result); } function nativePluginErrorHandler(error) { alert("ERROR: \r\n" + error); }\[/code\]Java:\[code\]@Overridepublic boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (action.equals("saveAdvertencia")) { advertenciaDS = new AdvertenciaDS(cordova.getActivity()); callbackContext.sendPluginResult(new PluginResult(Status.OK, new JSONArray("test"))); return true; } return false;}\[/code\]What I need is a way to retrieve the result from the action in the same method. It's very complicated to always deal with 3 methods(1 to execute the action. 1 to define what will be the success action. 1 to define what will be the error action.) when you don't really controll when they are called, since PhoneGap calls them after the action is completed.If I need to retrieve some data from the Android Native database:1 - Call in JavaScript the "cordova.exec".2 - PhoneGap will call your plugin.3 - Your plugin will return 2 things: A boolean for the PhoneGap defining it everything worked as expected or not. The data that will be passed to the sucessfull methods.4 - Here is the tricky part for me. If successfull or not, you have to create 2 methods that you dont have the controll of when they will be called, because PhoneGap will decide that. How do I change this?Is it possible in a simple way?
 
Back
Top