Java Reference
In-Depth Information
At any point, the AMS may signal to your MIDlet that it should terminate by invoking
its destroyApp method. When the AMS invokes destroyApp , the AMS passes a flag indicat-
ing the MIDlet has a choice to exit or not to exit. When this flag is false , your application
can signal the AMS not to exit by throwing a MIDletStateChangeException . It's up to the
platform provider to determine under what conditions a MIDlet exit is unconditional, so
your MIDlet design shouldn't rely on being able to control when it terminates.
Of course, you can trigger these state changes programmatically, too. If your MIDlet
wants to relinquish control to the AMS and enter the paused state, simply invoke
notifyPaused . In turn, the AMS will place your MIDlet in the paused state, although it will
do so without invoking your pauseApp method, because it will assume that you were pre-
pared to pause execution before you invoked notifyPaused . If you need to return to the
active state from the paused state, invoke resumeRequest ; the AMS will process your
request to resume and invoke your startApp method when it's ready to return your
MIDlet to the active state. In a similar vein, you can invoke notifyDestroyed to exit your
MIDlet; like notifyPaused , this does not signal your MIDlet through the destroyApp
method, but instead immediately terminates your MIDlet.
Caution Do not invoke System.exit from your MIDlet! The only way to exit your MIDlet is by calling
notifyDestroyed , which signals to the AMS that you wish to exit. Invoking System.exit from a MIDlet
generates a SecurityException .
Packaging MIDlets
As you learned in Chapter 3, devices obtain MIDlets through two files: JAD and JAR. The
JAD file contains a summary of the MIDlet's requirements for execution, and devices may
download this file to determine the suitability of the MIDlet for execution within the
device's Java ME environment. However, only the JAR file is actually required.
Within the JAR file is a manifest , named manfest.mf . The manifest exists at the root of
the JAR file and contains a detailed description of the contents of the JAR file. It consists
of name-value pairs, called MIDlet attributes , which are separated by colons and delim-
ited by newlines. Table 4-1 shows the attributes defined by the Java ME specifications. In
addition to the attributes shown in Table 4-1, you can pass additional attributes to the
MIDlet in the manifest; these are available by calling the MIDlet method getAppProperty
and passing the name of the attribute.
 
Search WWH ::




Custom Search