What is a MIDlet?
The Mobile Information Device Profile (MIDP) is a set of Java APIs targeted at mobile information devices such as mobile phones and entry-level palmtop devices. A MIDlet is a MIDP application. Throughout this article, the terms MIDlet and MID application are used interchangeably. MIDlets form the building blocks of the Java 2 Platform, Micro Edition (J2ME) runtime environment.
The MIDlet is designed to be run and controlled by the application manager in the K Virtual Machine (KVM), a stripped-down version of the Java Virtual Machine designed to run on mobile devices. The javax.microedition.midlet.MIDlet class acts as an interface between the MIDlet and the application manager. The methods of this class allow the application manager to create, start, pause, and destroy a MIDlet.
J2ME applications must extend the javax.microedition.midlet.MIDlet class, which provides a framework for the following actions:
* To allow the application manager to control the MIDlet by notifying and requesting MIDlet state changes.
* To allow the MIDlet to retrieve properties from the application descriptor, a registry of applications maintained by the application manager.
A MIDlet can be in various states in its lifetime. These states allow the application manager to manage the activities of multiple MIDlets within a runtime environment. It can select which MIDlets are active at a given time by starting and pausing them individually. The application manager also maintains the state of the MIDlet. A MIDlet can be in any of the following states:
* Active: The MIDlet enters an active state at startup and may acquire some resources.
* Paused: In the paused state, the MIDlet releases shared resources and becomes quiescent.
* Destroy: This is the MIDlet's termination phase. The terminating MIDlet must release all resources and save any persistent state with the application manager.
State implementations: Moving from state to state
The application manager invokes certain methods on the MIDlet to change states. The MIDlet implements these methods to update its internal activities and resource usage as directed by the application manager:
* startApp(): This method signals the MIDlet that it has entered an active state. It consists of the initialization procedures for setting up of an interactive display environment for the MIDlet.
* pauseApp(): This method signals the MIDlet to stop and enter the paused state.
* destroyApp(): This method signals the MIDlet to terminate and enter the destroyed state.
The MIDlet can initiate some state changes itself and notifies the application manager of those state changes by invoking one of these methods:
* notifyDestroyed(): This method is used by a MIDlet to notify the application manager that it has entered into the destroyed state.
* notifyPaused(): This method notifies the application manager that the MIDlet does not want to be active and has entered the paused state.
* resumeRequest(): This method provides a MIDlet with a mechanism to indicate that it is interested in entering the active state. Calls to this method can be used by the application manager to determine which applications to move to the active state. When the application manager decides to activate a MIDlet, it will call that MIDlet's startApp() method.
The MIDlet is provided with a mechanism to retrieve named properties from the application manager: its getAppProperty() method. These properties, provided as part of the MIDlet deployment, are retrieved from the combination of the application descriptor file and the manifest.
If a runtime exception occurs during startApp() or pauseApp(), the MIDlet will be destroyed immediately.