MIDlet Execution Environment and Lifecycle
All
MIDlets
are derived from the abstract base class
javax.microedition.midlet.MIDlet, which contains
methods that the MIDP platform calls to control the
MIDlet’s lifecycle, as well as methods that the
MIDlet itself can use to request a change in its state. A MIDlet must
have a public default
constructor (that is, a constructor that
requires no arguments), which may be one supplied by the developer if
there is any initialization to perform or, when there are no explicit
constructors, the empty default constructor inserted by the Java
compiler. This is what a skeleton MIDlet class might look like:
public class MyMIDlet extends MIDlet {
// Optional constructor
MyMIDlet( ) {
}
protected void startApp( ) throws MIDletStateChangedException {
}
protected void pauseApp( ) {
}
protected void destroyApp(boolean unconditional)
throws MIDletStateChangedException {
}
}At any given time, a MIDlet is in one of three states: Paused, Active, or Destroyed. A state diagram that shows how these states are related and the legal state transitions is shown in Figure 3-4.

Figure 3-4. The lifecycle of a MIDlet
When a MIDlet is loaded, it is initially in the Paused state. The usual class and instance initialization is then performed -- that is, static initializers are called the first time the MIDlet class is loaded, all instance initializers are invoked when the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access