cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Grieve <>
Subject Plugin Hooks on Android
Date Thu, 09 Jan 2014 02:58:41 GMT
Breaking out a discussion Joe & I started on

Some plugin hooks on Android are made available as functions on the
CordovaPlugin class. If you are interested in the hook, you override
the function.

Some hooks are made available through the onMessage(String name,
Object obj) function. Examples that I could find:

postMessage("spinner", "stop");
postMessage("exit", null);
postMessage("splashscreen", "show");
postMessage("onScrollChanged", myEvent); <-- data is a custom class
postMessage("onPageFinished", url);
postMessage("onPageStarted", url);
postMessage("onReceivedError", data); <-- data is a JSONObject
postMessage("onCreateOptionsMenu", menu); <-- a Menu object
postMessage("onPrepareOptionsMenu", menu);  <-- a Menu object
postMessage("onOptionsItemSelected", item); <-- a MenuItem object

The split seems about 50/50.

Now, what I'd like to propose is that we do away with postMessage
pattern. Reasons:
1. It will make what hooks exist much more discoverable
  - Right now there's no list of what postMessages exist within
2. It will make hook parameters typed
  - Right now you need to cast the second parameter of postMessage to
use it (e.g. to Menu, MenuItem, ScrollEvent, String, JSONObject).
3. Hooks can have multiple parameters
  - This would make sense for onScrollChanged and onReceivedError,
which use a custom object and a JSONObject to pass multiple params.

I actually didn't know half of these hooks existed, so I think even
just #1 is really compelling. We'd obviously need to keep delivering
these message for backwards-compatibility (except for maybe scroll -
it's pretty new)

View raw message