Namespaces
Variants
Actions

Enabling pauseApp() method calls in Java ME

Jump to: navigation, search


Article Metadata

Code Example
Tested with
Devices(s): Nokia 6650, Nokia E52

Compatibility
Platform(s): S60 3rd Edition, FP2

Article
Keywords: MIDlet.pauseApp(), MIDlet.startApp(), Nokia-MIDlet-Background-Event and Nokia-MIDlet-Flip-Close JAD attributes
Created: jarmlaht (21 May 2008)
Reviewed: skalogir (20 Aug 2012)
Last edited: skalogir (20 Aug 2012)

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:

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 20 August 2012, at 14:25.
303 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved