Most mobile apps require data from the Internet.
One
approach for
updating its data is that the
apps
periodically
polls a server for new
data (Polling). If
no new data is available this approach uses
unnecessary
network
bandwidth and consumes the battery of the mobile
phone.
An alternative approach is that
the server contacts the mobile
app once new data is available (Push). If the data does not
change
constantly, Push is the preferred solution.
As of Android 2.2 it is possible to push
information to an
Android app.
This service is
called
Cloud
to Device messaging
or short
C2DM.
In a C2DM you have three involved parties. The application
server which
wants to push messages to the Android device,
Googles C2DM
servers
and the Android
app. The program on the application server can
be written in
any programming language, e.g. Java, PHP, Python, etc.
When the application server needs to push a
message to
the Android
application, it
sends the message via an HTTP POST to
Google’s C2DM
servers.
The C2DM servers route the message to the
device. If the device
is not online, the message will be delivered once the device
is
available. Once the message is received, an
Broadcast Intent is
created. The mobile app has registered an Intent Receiver for this
Broadcast. The app is started
and processes the
message via the
defined
Intent Receiver.
C2DM
messages are limited in
size to 1024 bytes and are intended
to inform the device about new
data not to transfer it.
The typical
workflow is that Googles C2DM servers notify
the
Android
app
that new
data is available. Afterwards the
Android
app
fetches the data
from a
different server.