he 2.0 release of MIDP includes a number of enhancements that help developers write Java applications for devices. One of the most intriguing new features is "push," which provides a way for a MIDlet to respond to network activity regardless of whether it is currently running. Among other things, push can be used to integrate wireless messaging into applications or proactively contact the user about something of interest to them. Applications can even run as a service by responding to an inbound network connection, performing a task and then shutting down. All of this can occur with little or no user interaction.
MIDlets, in a sense, can now run like a service on a device to handle certain tasks without the user explicitly needing to start the application. With the addition of push, MIDP applications gain prominence on the device, much like SMS and the phone call features of a cell phone, rather than being tucked off to the side under some obscure menu.
In this article we'll delve into the details of the MIDP 2.0 push features and demonstrate how the PushRegistry can be used to enhance your mobile applications.
What Are the Parts of Push?
At the heart of MIDP 2.0 push are two components: the javax.microedition.io.PushRegistry class and the Application Management Software (AMS). The PushRegistry provides the interface for managing network connections related to push. The AMS participates by monitoring network activity and starting an associated MIDlet (if it's not already running) in response to network activity over a certain port.
Here's how it works: A MIDlet registers a connection, such as a socket or datagram, with the PushRegistry. This can either be done statically, by specifying the connection string in the application descriptor and distributing it with the application, or dynamically, using the PushRegistry class at runtime. When the AMS detects an incoming connection associated with a MIDlet, the AMS starts the MIDlet and calls the startApp()
method. At this point the MIDlet takes over responsibility for the connection and performs the steps necessary for handling the incoming connection.
If the MIDlet is already running, however, it is important to understand that the AMS does not get involved. This is because once a MIDlet is running it can listen for and handle inbound connections without AMS assistance.
On the next page I'll discuss push registration in more detail.