5
Application Management
| pauseApp() | AMS, MIDlet | The pauseApp() method is called from either AMS or |
|
|
| from within the MIDlet. |
|
|
| The pauseApp() should pause active threads, and |
|
|
| prepare for startApp() to be called. |
|
|
| If the application is to be resumed with a screen other than |
|
|
| the present, then the Displayable should be set current in |
|
|
| the startApp() or the pauseApp(). |
| destroyApp() | AMS | The destroyApp() method is called from AMS and |
|
|
| signals the MIDlet to clean up any resources to prepare for |
|
|
| termination. For example, open RMS records should be |
|
|
| closed, threads should be stopped, and any other |
|
|
| housekeeping chores should be performed. |
|
|
| The MIDlet should not call destroyApp(). |
|
|
|
|
| notifyDestroy | MIDlet | The notifyDestroyed() method is called by the |
| ed() |
| MIDlet to exit and terminate itself. |
|
|
| All housekeeping such as stopping active threads and |
|
|
| closing RMS records should be performed before calling |
|
|
| notifyDestroyed(). |
|
|
| notifyDestroyed() notifies AMS to terminate the |
|
|
| calling MIDlet. |
|
|
|
|
On a device without a windowing system, only one application can have focus at a time. When an application has focus, it receives keypad input, and has access to the display, speakers, LED lights, vibrator, etc. The C370, C450, and C550 device can only run one MIDlet at a time, but that MIDlet has to share focus with the system user interface. That user interface is a higher priority than the MIDlet, so the MIDlet will immediately lose focus when the system needs to handle a phone call or some other interrupt.
The concept of focus correlates directly with the MIDlet state. i.e. when a MIDlet loses focus because of a phone call, the MIDlet is immediately paused. Conversely to the example of starting the MIDlet, the MIDlet loses focus immediately, then its pauseApp() method is called.
The paused state is not clearly defined by MIDP. The only requirement placed on the device manufacturer is that a paused MIDlet must be able to respond to network events and timer events. On Motorola devices, the paused state simply implies that the MIDlet is in the background as mentioned above, but it doesn’t force any of the threads to stop execution. Essentially, a paused MIDlet is a MIDlet without focus whose pauseApp() method has been called. It’s up to the developer to control their threads, such as making them sleep for longer periods, completely pausing game threads, or terminating threads that can be restarted when the MIDlet is made active again.
Similarly, a MIDlet’s focus is also lost immediately before its destroyApp() method is called.
The MIDlet must be written properly (as described above) to implement all methods in the javax.microedition.midlet package, especially startApp( ) and pauseApp( ). A
27