ColdFusion MX Professional Projects
In Chapter 2, you got a quick introduction to the process of building and running MIDlets. In this chapter, we'll explore the details. We'll cover the subjects that we skimmed in last chapter, starting with the MIDlet life cycle and continuing through to a full discussion of MIDlet packaging.
The MIDlet Life Cycle
MIDP applications are represented by instances of the javax.microedition.midlet.MIDlet class. MIDlets have a specific life cycle, which is reflected in the methods and behavior of the MIDlet class.
A piece of device software outside the realm of Java, the application manager, controls the installation and execution of MIDlets. A MIDlet is installed by moving its class files to a device. The class files will be packaged in a Java Archive (JAR), while an accompanying descriptor file (with a .jad extension) describes the contents of the JAR.
A MIDlet goes through the following states:
-
When the MIDlet is about to be run, an instance is created. The MIDlet's constructor is run, and the MIDlet is in the Paused state.
-
Next, the MIDlet enters the Active state after the application manager calls startApp().
-
While the MIDlet is Active, the application manager can suspend its execution by calling pauseApp(). This puts the MIDlet back in the Paused state. A MIDlet can place itself in the Paused state by calling notifyPaused().
-
The application manager can terminate the execution of the MIDlet by calling destroyApp(), at which point the MIDlet is Destroyed and patiently awaits garbage collection. A MIDlet can destroy itself by calling notifyDestroyed().
Figure 3-1 shows the states of a MIDlet and the transitions between them.
There is one additional method in the MIDlet class related to the MIDlet life cycle: resumeRequest(). A MIDlet in the Paused state can call this method to signal to the application manager that it wants to become Active. It might seem weird to think about a MIDlet in the Paused state running any code at all. However, Paused MIDlets are still able to handle timer events or other types of callbacks and thus have some chances to call resumeRequest(). If the application manager does decide to move a MIDlet from the Paused to the Active state, it will do so through the normal mechanism of calling startApp().
Team-Fly |