×
Namespaces

Variants
Actions

Enabling pauseApp() method calls in Java ME

From Nokia Developer Wiki
Jump to: navigation, search

Contents

Version Hint

Windows Phone: [[Category:Windows Phone]]
[[Category:Windows Phone 7.5]]
[[Category:Windows Phone 8]]

Nokia Asha: [[Category:Nokia Asha]]
[[Category:Nokia Asha Platform 1.0]]

Series 40: [[Category:Series 40]]
[[Category:Series 40 1st Edition]] [[Category:Series 40 2nd Edition]]
[[Category:Series 40 3rd Edition (initial release)]] [[Category:Series 40 3rd Edition FP1]] [[Category:Series 40 3rd Edition FP2]]
[[Category:Series 40 5th Edition (initial release)]] [[Category:Series 40 5th Edition FP1]]
[[Category:Series 40 6th Edition (initial release)]] [[Category:Series 40 6th Edition FP1]] [[Category:Series 40 Developer Platform 1.0]] [[Category:Series 40 Developer Platform 1.1]] [[Category:Series 40 Developer Platform 2.0]]

Symbian: [[Category:Symbian]]
[[Category:S60 1st Edition]] [[Category:S60 2nd Edition (initial release)]] [[Category:S60 2nd Edition FP1]] [[Category:S60 2nd Edition FP2]] [[Category:S60 2nd Edition FP3]]
[[Category:S60 3rd Edition (initial release)]] [[Category:S60 3rd Edition FP1]] [[Category:S60 3rd Edition FP2]]
[[Category:S60 5th Edition]]
[[Category:Symbian^3]] [[Category:Symbian Anna]] [[Category:Nokia Belle]]

Article Metadata
Code ExampleTested with
Devices(s): Nokia 6650, Nokia E52
CompatibilityArticle
Created: jarmlaht (21 May 2008)
Reviewed: skalogir (20 Aug 2012)
Last edited: lpvalente (07 Sep 2013)

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.pngNote: 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 foreground again:

MIDlet-1: HelloMIDlet, , HelloMIDlet
MIDlet-Jar-Size: <your jar file size>
MIDlet-Jar-URL: HelloWorld.jar
MIDlet-Name: HelloWorld
MIDlet-Vendor: Nokia Developer
MIDlet-Version: 1.0
MicroEdition-Configuration: CLDC-1.1
MicroEdition-Profile: MIDP-2.0
Nokia-MIDlet-Background-Event: pause

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.

See also

JAD and JAR manifest attributes

How to handle MIDlet sent to the background

This page was last modified on 7 September 2013, at 20:24.
113 page views in the last 30 days.