Pausing a MIDlet
Note: The pauseApp() method is not supported in Series 40 GSM/WCDMA devices. However, it is supported in CDMA devices for some operators.
In many cases it is useful or even necessary to have the MIDlet pause itself automatically. For example, all possible system notifications are shown over the MIDlet, thus the MIDlet is hidden in the background. Note that with Series 40 devices, a phone call, for example, interrupting the application is the only way for the application to enter the Paused state.
MIDP specifications define that a system can set MIDlets to the paused state (the pauseApp() method) if the system needs a lot of the device’s resources. In the paused state, the MIDlet frees all its resources. The currently available Series 60 devices have sufficient running power and memory, and they do not need to enter the Paused state. This means that you must create your own pausing mechanisms.
In other words, you must create a method that pauses an active session when one of the following events occurs during the MIDlet interaction:
A system notification is shown on the screen (for example, an incoming call, or notification of battery full or low).
The user presses the red dial key, the power key or the application key of the device.
The main screen of the application is hidden by a system menu, or another application is set to run on the foreground.
In practice, the MIDlet must always be paused when it is hidden. This is especially important in game applications, because the player will probably lose the game if it is not immediately paused when the game is hidden.
MIDlets can be paused with the isShown() method of the Displayable class or the hideNotify() method of the Canvas class.
All User Interface (UI) components are inherited from the Displayable class. Thus, the isShown() method can be used to test whether a UI component is visible or not. Repetitive requesting of the isShown() method can be used to get information if the UI component is hidden for some reason. The isShown() method can be used for high-level UI components like Form or List, but in case of low-level UI components that are inherited from Canvas class it is better to use its proprietary hideNotify() method.
The hideNotify() method is called right after the Canvas object has left the display. Create an auto-pause mechanism inside the hideNotify() method to stop threads, cancel timers, save important values, and so on.
After the paused session is ready to be continued, the Continue option needs to be shown to the user. It can be, for example, one entry of the main menu of the application.
The application can be paused when any interruption happens.
The MIDlet pauses itself automatically if it is hidden.
It is possible to choose to continue the application after the interruption.