直接贴代码。。切入正题!
package src;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class LifecycleTest extends MIDlet implements CommandListener
{
private Form form;
private Command quit;
private boolean forceExit =false;
public LifecycleTest()
{
System.out.println("Constructor called.");
form =new Form("Life ,Jason.");
form.append("But not as we know it.");
form.setCommandListener(this);
quit = new Command("Quit", Command.SCREEN, 1);
form.addCommand(quit);
}
protected void destroyApp(boolean b) throws MIDletStateChangeException
{
System.out.println("destroyApp("+ b+ ") called.");
if(!b)
{
forceExit = true;
}
}
protected void pauseApp()
{
System.out.println("pauseApp() called.");
}
protected void startApp() throws MIDletStateChangeException
{
System.out.println("startApp() called.");
Display.getDisplay(this).setCurrent(form);
}
public void commandAction(Command c, Displayable d)
{
System.out.println("commandAction(" +c +","+d +") called.");
try
{
if(c == quit)
{
destroyApp(forceExit);
notifyDestroyed();
}
}
catch (MIDletStateChangeException e)
{
System.out.println(e +"caught.");
}
}
}