1

I'm programming a J(2)ME app (actually a MIDlet) where more commands than command buttons available are shown on the screen and I'm stuck with this situation:

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

So in this situation a Menu is auto-generated and a 'Select' and 'Back' choice added. The 'Back' choice is supposed to exit the menu and go back to the previous screen. This works in principle, problem is I need to catch it somehow and trigger a redraw, otherwise the screen goes blank.

So my question is: Is there a way to catch this 'implicit' (automatically added 'Back' command ?

Code example and result:

enter image description here

 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)
    {
    }
}

edit to add more detail:

As per my comment, I'm going back from a Form to Canvas in my app, that's where the screen blanking happens. I've already added my own 'Back' command, this one works correctly as I can catch easily with CommandListener and treat accordingly (trigger a redraw). But now I have two 'Back' commands, the implicit one (blanking) and mine. So the alternative version of the question is: Can I prevent the adding of the implicit 'Back' command somehow ?

nofish
  • 115
  • 2
  • 10
  • When you say "I need to catch it somehow and trigger a redraw, otherwise the screen goes blank" it looks like your real application is based on Canvas, not Form. Am I right? – Telmo Pimentel Mota Jun 08 '16 at 10:15
  • You're absolutely right. In my real app I'm going from Form via 'Back' back to Canvas, that's when the screen goes blank. – nofish Jun 09 '16 at 10:51
  • Did you check if sizeChanged or showNotify are called? – Telmo Pimentel Mota Jun 09 '16 at 13:20
  • Sorry for coming back to this with a delay. These functions were unknown to me, I checked and showNotify is indeed called when executing the blanking 'Back' command. So that's a good hint, thanks. Problem is though, it's called several times during running the app (e.g. when starting, coming back from another Canvas) so it's not something I can use to handle this specific situation I think. sizeChanged isn't called at all when the extended menu appears. – nofish Jun 13 '16 at 23:07
  • You can't prevent the adding of the implicit 'Back' command, but you can redraw the screen from the call to showNotify. – Telmo Pimentel Mota Jun 14 '16 at 13:24
  • Thanks. You can post this as regular answer if you want, so I can accept it. – nofish Jun 16 '16 at 09:49

1 Answers1

1

You can't prevent the adding of the implicit 'Back' command, but you can redraw the screen from the call to 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.

Telmo Pimentel Mota
  • 4,033
  • 16
  • 22