« Back to blog

PhoneGap 1.0 Android Plugin updates

With the upcoming release of PhoneGap 1.0 I thought I would point out a couple of nice additions coming for PhoneGap (Android) Plugin developers (and eventually PhoneGap as a whole).

The first addition is the propagation of lifecycle events (onPause, onResume and onNewIntent) to plugins. Plugin developers are now responsible for reacting appropriately if the app has multitasking turned on, but also have access to the lifecycle of the application. Developing the NFC plugin (https://github.com/chariotsolutions/phonegap-nfc) we found this an absolute necessity, so it’s great to see it added in.

Ah the power of Open Source software :)

The second is a new method of loading plugins. To register a plugin now you just need to add your plugin name and class to the plugins.xml (located in res/xml/)

In your JavaScript companion file you can just create a ‘new plugin’, removing the messy addConstructor/addService calls we had before.

An updated example from the ToastPlugin (https://github.com/m00sey/Toasty)

Usage:

This move to plugins.xml is going to be part of a broader PhoneGap wide move to using cross-platform ‘config.xmls’ (a sneak peak here: https://github.com/filmaj/phonegap-android/blob/feature/example/config.xml#L2...) bringing PhoneGap so much closer to truly, write once run everywhere; exciting stuff!