从lwuit表单中调用destroyApp(true)

时间:2011-07-19 23:44:56

标签: java-me lwuit midp

我想关闭正在运行的midlet。但Display上的当前项目是一个lwuit表格。如何通过单击添加到lwuit表单的命令来关闭应用程序。

1 个答案:

答案 0 :(得分:2)

传递midlet实例并致电destroyApp(...)或使用notifyDestroyed();

例如,

<强> Sample.java

public class Sample extends MIDlet {

public Sample() {

  // do something
  new Sample1(this); // pass the MIDlet to another class.
 }
}

<强> Sample1.java

public class Sample1 {
public Sample1(final MIDlet midlet) {

  // do something
  Command exitCmd = new Command("Exit") {

            public void actionPerformed(ActionEvent evt) {
                midlat.notifyDestroyed();
            }
        };
 }
}