Google I/O day 2: The Android push messaging API
As I mentioned in my earlier post about the keynote, one of the exciting new releases at I/O is the new Push messaging API for Android. With it, you can push notifications from any webapp to an Android device in real-time - no polling, no messy hacks.
Push messaging is particularly valuable on the Android, because of battery life concerns. Even a single app polling every 5 minutes can cause a substantial drain on the battery - mostly wasted on checking for changes that don't exist. Several Android APIs already use push for sync - including Contacts, CAlendar, and the GMail app. Implementing it yourself, and getting it right, is tough, though - and that's where the new API comes in.
Under the hood, this is implemented as a background service. It starts whenever the network is available, and maintains a connection with the server for new messages. In order to prevent NATs and other network hardware from destroying the connection, and to detect that if it happens, it uses heartbeat messages - but it's been extensively tested and optimized to minimise the frequency of these as much as possible.
To use it, an app on the Android device registers with Google, and gets back a registration ID. It then sends that ID to the webapp - via whatever mechanism it chooses. To send a message to the device, the webapp sends an authenticated message to the Android push API, which takes care of delivering it to the device. The push messages themselves consist mostly of a notification of new data, so it's up to the app to actually fetch the new data directly from the webapp.
I'll go into more detail, with a practical example of building cooperating App Engine and Android apps, in a future post. If you've got some suggestions on what would make a good demo, let me know in the comments.Previous Post Next Post