/** * Receives a request for execution and fulfills it by finding the appropriate * Java class and calling it's execute method. * * PluginManager.exec can be used either synchronously or async. In either case, a JSON encoded * string is returned that will indicate if any errors have occurred when trying to find * or execute the class denoted by the clazz argument. * * @param service String containing the service to run * @param action String containing the action that the class is supposed to perform. This is * passed to the plugin execute method and it is up to the plugin developer * how to deal with it. * @param callbackId String containing the id of the callback that is execute in JavaScript if * this is an async plugin call. * @param rawArgs An Array literal string containing any arguments needed in the * plugin execute method. */ public void exec(final String service, final String action, final String callbackId, final String rawArgs) { if (numPendingUiExecs.get() > 0) { numPendingUiExecs.getAndIncrement();//获取并自增 this.ctx.getActivity().runOnUiThread(new Runnable() { public void run() { execHelper(service, action, callbackId, rawArgs); numPendingUiExecs.getAndDecrement();//获取并自减 } }); } else { execHelper(service, action, callbackId, rawArgs); } }
代码如上,小弟最近在看cordova,对于 PluginManager.exec can be used either synchronously or async,这句很不理解,希望大神们帮助解答一下,还有cordova是怎么实现同步和异步的?最好详细一些,小弟对此研究不深.