Cordova / phonegap活动生命周期 [英] Cordova/phonegap activity lifecycle
问题描述
我正在为一个科尔多瓦应用程序中的Android地图插件工作(让我们暂时忘记已经有不止一个在野外,并认为这是一个学术问题), MapView的文档$ c $
$ b
此类的用户必须将包含此视图的Activity或Fragment的所有生命周期方法转发给在这个类中相应的。
也就是说,我需要在我的地图上至少调用
onResume()
onPause()
onDestroy()
onLowMemory()
方法。 Cordova / Phonegap有没有办法做到这一点?请记住,我正在使用 CordovaPlugin
的子类,与每个插件一样,而不是在 Activity
正确(我无法触及,至少是代码方式)。
谢谢!
public void onPause(boolean multitasking)
public void onResume(boolean multitasking)$ b $ public void onDestroy()
等等,这些回答了我的问题。所有你需要做的就是在插件中实现它们,至少部分生命周期可以用这种方式处理。
至于缺少的方法( onCreate
, onRestart
等),因为无论插件何时进入游戏,cordova活动都已创建。
希望这可以帮助任何有同样问题的人
I'm working on a map plugin for android in a cordova application (let's forget for a second that there is already more than one in the wild, and consider this an academical question), the documentation for MapView
states:
Users of this class must forward all the life cycle methods from the Activity or Fragment containing this view to the corresponding ones in this class. [...]
That is, I need to appropriately call on my map at least the
onResume()
onPause()
onDestroy()
onLowMemory()
methods. Is there a way to do that with Cordova/Phonegap? Keep in mind that I'm working in a subclass of CordovaPlugin
, as with every plugin, and not in the Activity
proper (which I cannot touch, code-wise at least).
Thank you!
How silly of me: the CordovaPlugin
class forwards the methods:
public void onPause(boolean multitasking)
public void onResume(boolean multitasking)
public void onDestroy()
among the others, which answers my question. All you need to do is implement them in the plugin and at least part of the lifecycle can be handled in this way.
As for the missing methods (onCreate
, onRestart
, etc), having them would make no sense, as the cordova activity is already created when whatever plugins enters the game.
Hope this helps anyone with the same problem
这篇关于Cordova / phonegap活动生命周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!