Pass J2ME (1)-MIDP state

Source: Internet
Author: User
For the MIDlet state, there is a application management software is specifically responsible for management. All you have to care about is how to deal with this am.

Pauseapp ()
Destroyapp ()
STARTAPP ()

Rewrite these three methods. Am will be invoked at the appropriate time.

and
Notifydestroyed ()
Notifypaused ()
Resumerequest ()
is to give you a chance to tell am what to do.

Here is a simple example that can be tested according to your own expansion. One thing that's odd is that, theoretically, when MIDlet is in an active state, AM will call Pauseapp () if there is a phone entry. However, the actual test did not find that am calling this method.

Package net.csdn.blog.vincint;

Import javax.microedition.midlet.*;
Import javax.microedition.lcdui.*;

/**
* This is a simple test to help me understanding the Midlet State
*
* <p>title:midlet test</p>
* <p>description: </p>
* <p>copyright:copyright (c) 2005</p>
* <p>Company:http://blog.csdn.net/Vincint</p>
* @author Vincint
* @version 1.0
*/
public class Midletstate
Extends MIDlet
Implements
Commandlistener {
protected form form;
protected Command exitcmd;
protected Command debugcmd;
protected display display;
protected String Debug;
Public Midletstate () {
Adddebuginfo ("in Midletstate ()");
display = Display.getdisplay (this);
form = new Form ("Hello world.");
Form.append ("What a new world!");
Exitcmd = new Command ("Exit", Command.exit, 1);
Debugcmd = new Command ("Debug", Command.screen, 2);
Form.addcommand (Exitcmd);
Form.addcommand (Debugcmd);
Form.setcommandlistener (this);
}

/**
* STARTAPP
*/
protected void startApp () {
Adddebuginfo ("in StartApp ()");
Display.setcurrent (form);
}

/**
* Pauseapp
*/
protected void Pauseapp () {
Adddebuginfo ("in Pauseapp ()");
}

/**
* Destroyapp
*
* @param Boolean0 Boolean
*/
protected void Destroyapp (Boolean boolean0) {
Adddebuginfo ("In Destroyapp" ("+ Boolean0 +"));
}

/**
* Commandaction
*
* @param command command
* @param displayable displayable
*/
public void commandaction (Command command, displayable displayable) {
Adddebuginfo ("in Commandaction (...)");
if (Command = = Exitcmd) {
Destroyapp (TRUE);
Notifydestroyed ();
}
else if (Command = = Debugcmd) {
Notifyuser (debug, form);
}
}

Protected string Adddebuginfo (string debugmsg) {
if (debug = = null) {
debug = new String ();
}
debug = Debug.concat (debugmsg + "\ n");
return debugmsg;
}

protected void Notifyuser (String message, displayable screen) {
Alert alert = new Alert ("Info", message, NULL, alerttype.info);
Alert.settimeout (Alert.forever);
Display.setcurrent (alert, screen);
}
}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.