问题描述:

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

相关阅读:
Top