Chapter 3: All About MIDlets

Team-Fly

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:

  1. 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.

  2. Next, the MIDlet enters the Active state after the application manager calls startApp().

  3. 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().

  4. 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.

click to expand
Figure 3-1: MIDlet life cycle

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


Wireless Java. Developing with J2ME
ColdFusion MX Professional Projects
ISBN: 1590590775
EAN: 2147483647
Year: 2000
Pages: 129

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net