The MIDletStateHandler starts and controls MIDlets through the lifecycle states. MIDlets are created using its no-arg Constructor. Once created a MIDlet is sequenced through the
ACTIVE
,
PAUSED
, and
DESTROYED
states.
The MIDletStateHandler is a singleton for the suite being run and is retrieved with getMIDletStateHandler(). This allow the MIDletStateHandler to be the anchor of trust internally for the MIDP API, restricted methods can obtain the MIDletStateHandler for a MIDlet suite inorder to check the properties and actions of a suite. Because of this, there MUST only be one a MIDlet suite per MIDletStateHandler. In addition a method can assume that the application manager is the caller if there is no suite started.
The MIDlet methods are protected in the javax.microedition.midlet package so the MIDletStateHandler can not call them directly. The MIDletState object and MIDletTunnel subclass class allow the MIDletStateHandler to hold the state of the MIDlet and to invoke methods on it. The MIDletState instance is created by the MIDlet when it is constructed.
This implementation of the MIDletStateHandler introduces extra internal MIDlet states to allow processing of MIDlet requested state changes in the control thread and serialized with other state changes. The additional states are:
-
ACTIVE_PENDING
- The MIDlet is still PAUSED but will be ACTIVE
after startApp is called when the state is next processed. -
PAUSE_PENDING
- The MIDlet is still ACTIVE but will be PAUSED
after pauseApp is called when the state is next processed. -
DESTROY_PENDING
- Indicates that the MIDlet needs to be DESTROYED
. The MIDlet's destroyApp has not yet been called.
The MIDletStateHandler loops, looking for MIDlets that require state changes and making the requested changes including calling methods in the MIDlet to make the change.
When a MIDlet's state is changed to ACTIVE
, PAUSED
, or DESTROYED
the MIDlet state listener is notified of the change, which in turn sends the notification onto the central AMS.
@see MIDlet
@see MIDletPeer
@see MIDletLoader
@see MIDletStateHandler