FileDocCategorySizeDatePackage
HeadlessAlert.javaAPI DocphoneME MR2 API (J2ME)3835Wed May 02 18:00:06 BST 2007com.sun.midp.main

HeadlessAlert

public class HeadlessAlert extends Alert implements CommandListener
HeadlessAlert is shown when a user selects a MIDlet to bring to the foreground that has not requested the foreground at least once by call Display.setCurrent(Displayable).

Fields Summary
private MIDletControllerEventProducer
midletControllerEventProducer
Cached reference to the MIDletControllerEventProducer.
private int
displayId
ID of the parent display
private Command
backgroundCommand
Command to bring a headless midlet into the background
private Command
exitCommand
Command to terminate a headless midlet
Constructors Summary
HeadlessAlert(int theDisplayId, MIDletControllerEventProducer theMidletControllerEventProducer)
Initialize this headless alert.

param
theDisplayId ID of the parent display
param
theMidletControllerEventProducer reference to an event producer

        super(null,
              Resource.getString(ResourceConstants.LCDUI_DISPLAY_HEADLESS),
              null, AlertType.INFO);

        displayId = theDisplayId;
        midletControllerEventProducer  = theMidletControllerEventProducer;

        setTimeout(Alert.FOREVER);

        // Don't put the background command on the main display's alert
        if (!MIDletSuiteUtils.isAmsIsolate()) {
            backgroundCommand = new Command(Resource.getString(
                                ResourceConstants.OK), Command.OK, 2);
            addCommand(backgroundCommand);
        }

        exitCommand = new Command(Resource.getString(ResourceConstants.EXIT),
                                  Command.EXIT, 1);

        addCommand(exitCommand);

        setCommandListener(this);
    
Methods Summary
public voidcommandAction(Command c, Displayable d)
Process commands for this alert. "OK" will dismiss the alert with no action. "Exit" will destroy the MIDlet.

param
c command the user pressed
param
d this displayable(not used)

        if (c == exitCommand) {
            /**
             * We need to destroy current midlet -
             * the owner of this alert:
             * to generate MIDLET_DESTROY_REQUEST
             * event for a given midlet to MIDlet Controller
             * in AMS Isolate.
             */
            midletControllerEventProducer.sendMIDletDestroyRequestEvent(
                displayId);
        } else if (c == backgroundCommand) {
            midletControllerEventProducer.sendDisplayBackgroundRequestEvent(
                displayId);
        }