简体   繁体   English

多次调用时与Cordova.exec相关的查询

[英]Query related to Cordova.exec when called multiple times

I am using cordova to make calls to the plugin file. 我正在使用cordova调用插件文件。

cordova.exec(onFileSystemSuccess, onFileSystemFailure, "ABCPlugin", "echo",[arg1, arg2]);

If the exec function is called 2 or more time I need a way to initialize the object only once. 如果exec函数被调用2次或更多次,我需要一种仅初始化一次对象的方法。

eg StandardFileSystemManager manager = new StandardFileSystemManager(); 例如,StandardFileSystemManager管理器=新的StandardFileSystemManager(); // which will be in the plugin file //将在插件文件中

But use only the once created value of the manager object. 但是,只能使用管理器对象的一次创建的值。

ie Say exec call calls the plugin file once, the object manager gets created. 即说执行调用一次调用插件文件,创建对象管理器。 The second time exec is called I want to reuse the value of manager object already initialize. 第二次调用exec我想重用已经初始化的管理器对象的值。

Hope this is clear or else let me know. 希望这很清楚,否则让我知道。 I just want to know if this is possible so that, the I will not have to created the manager object multiple times 我只想知道是否有可能,这样就不必多次创建管理器对象

You can store your manager variable as a member variable in your Java class of plugin, make it null at start (constructor), and check if it is still null when you receive init call and create it accordingly. 您可以将manager变量作为成员变量存储在插件的Java类中,在启动时将其设置为null(构造函数),并在接收到init调用时检查它是否仍然为null并相应地创建它。 Cordova plugin classes are (singletons) created once in app lifetime, you are always using the same instance. Cordova插件类在应用程序生命周期中创建一次(单个),您始终使用相同的实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM