如何捕获隐式菜单 'Back' 命令?

How to catch implicit menu 'Back' command?

我正在编写一个 J(2)ME 应用程序(实际上是一个 MIDlet),屏幕上显示的命令多于可用的命令按钮,我遇到了这种情况:

The mapping to concrete user interface constructs may also depend on the total number of the commands. For example, if an application asks for more abstract commands than can be mapped onto the available physical buttons on a device, then the device may use an alternate human interface such as a menu. For example, the abstract commands that cannot be mapped onto physical buttons are placed in a menu and the label "Menu" is mapped onto one of the programmable buttons.

http://docs.oracle.com/javame/config/cldc/ref-impl/midp2.0/jsr118/javax/microedition/lcdui/Command.html

因此在这种情况下会自动生成一个菜单,并添加了 'Select' 和 'Back' 选项。 'Back' 选项应该退出菜单并返回上一屏幕。这原则上是可行的,问题是我需要以某种方式捕获它并触发重绘,否则屏幕会变黑。

所以我的问题是:有没有办法捕获这个 'implicit'(自动添加的 'Back' 命令?

代码示例和结果:

 public class HelloWorld extends MIDlet
  {
    private Form helloFrm; 
    private Display display;

    public HelloWorld() {
      Command command1 = new Command("Cmd 1", Command.SCREEN, 1);
      Command command2 = new Command("Cmd 2", Command.SCREEN, 0);
      Command command3 = new Command("Cmd 3", Command.SCREEN, 0);
      Command command4 = new Command("Cmd 4", Command.SCREEN, 0);

      helloFrm = new Form("Hello World");

      helloFrm.addCommand(command1);
      helloFrm.addCommand(command2);
      helloFrm.addCommand(command3);
      helloFrm.addCommand(command4);
    }

    public void startApp()
    {
        display = Display.getDisplay(this);
        display.setCurrent(helloFrm);

    }

    public void pauseApp()
    {
    }

    public void destroyApp(boolean unconditional)
    {
    }
}

编辑以添加更多详细信息:

根据我的评论,我将在我的应用程序中从表单返回到 Canvas,这就是屏幕消隐发生的地方。 我已经添加了我自己的 'Back' 命令,这个命令正常工作,因为我可以使用 CommandListener 轻松捕捉并进行相应处理(触发重绘)。但是现在我有两个 'Back' 命令,隐式命令(消隐)和我的命令。 所以问题的替代版本是:我可以以某种方式阻止添加隐式 'Back' 命令吗?

您无法阻止添加隐式 'Back' 命令,但您可以通过对 Canvas.showNotify:

的调用重绘屏幕

The implementation calls showNotify() immediately prior to this Canvas being made visible on the display. Canvas subclasses may override this method to perform tasks before being shown, such as setting up animations, starting timers, etc. The default implementation of this method in class Canvas is empty.