Enabling pauseApp() method calls in Java ME
Article Metadata
Code Example
Tested with
Compatibility
Article
Contents |
Overview
This code snippet demonstrates how to enable MIDlet.pauseApp() method calls in MIDlets. There are some new JAD attributes in the S60 3rd Edition FP2 Java ME implementation, which can be used to enable this:
Nokia-MIDlet-Background-Event: pause
The system will call pauseApp for the MIDlet if the application is set to the background and if the value of the Nokia-MIDlet-Background-Event attribute is "pause". If the value is "run", or any other value than "pause", or no attribute or value is given, the pauseApp is not called.
Note: The startApp is called accordingly when the MIDlet is set again to the foreground.
Nokia-MIDlet-Flip-Close: pause
The system will call pauseApp() for the MIDlet if the device flip is closed and if the value of the Nokia-MIDlet-Flip-Close attribute is "pause". If the value is "run", or any other value than "pause", or no attribute or value is given, the pauseApp() is not called.
Note: The startApp() is called accordingly when the flip is opened again.
To test this, compile and run the following MIDlet. Make sure you have either of the two attributes in the JAD file. Put the MIDlet to the background and bring it to the foregroung again:
Source
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class HelloMIDlet extends MIDlet implements CommandListener {
private Form form;
private Command exitCommand;
public void startApp() {
if (form == null) { // Create the Form and Command only once
form = new Form("HelloMIDlet");
exitCommand = new Command("Exit", Command.EXIT, 1);
form.addCommand(exitCommand);
form.setCommandListener(this);
}
Display.getDisplay(this).setCurrent(form);
form.append("startApp()\n");
}
public void pauseApp() {
form.append("pauseApp()\n");
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
if (c == exitCommand) this.notifyDestroyed();
}
}
Postconditions
When the MIDlet is once put to the background and brought back to the foreground, the text "startApp() pauseApp() startApp()" should be on the Form.


(no comments yet)