1

The application is running , the user is making some TextField editing. Then a call is received , so the MIDlet enters the paused state. When the conversation is finished then the application is restarted , the startApp() method of the MIDlet is called and the main Form of the application is shown !

So how to dismiss this default behaviour so that the last opened Form with all the modifications are kept ?

Mun0n
  • 4,438
  • 4
  • 28
  • 46
pheromix
  • 18,213
  • 29
  • 88
  • 158
  • Display the current Form in PauseApp() – Lucifer Dec 20 '11 at 07:30
  • That doesn't work : I create in the midlet a `public static com.sun.lwuit.Form lastForm = null;` and in the constructor of a Form I make : `myMidlet.lastForm = this;`. Then in the `pauseApp()` I code : `lastForm.showBack();` but the main Form is always shown ! The last Form is shown just a fraction of a second but the main Form is then opened ! – pheromix Dec 20 '11 at 07:49
  • did you test this with plain lcdui forms instead of ones provided by lwuit? – gnat Dec 20 '11 at 07:52
  • 99% of my Forms are lwuit Forms , there is just one canvas in the project. – pheromix Dec 20 '11 at 07:54

2 Answers2

1

I created a static Form in the MIDlet class :

public static Form lastForm = null;

Then I set it to the actual Form in every Form of my project :

if (!myMidlet.lastCanvas.isEmpty())
    myMidlet.lastCanvas.clear();    
myMidlet.lastForm = this;

Then in the startApp() I wrote :

public void startApp() {
        ...
        if (lastForm != null)
            lastForm.showBack();
        else
        {
            new MainForm(this).show();
        }
    }

EDIT :

For the canvas :

In the MIDlet class :

public static Hashtable lastCanvas = new Hashtable();

In the canvas class ( constructor ) :

if (myMidlet.lastForm != null)
    myMidlet.lastForm = null;

if (!myMidlet.lastCanvas.isEmpty())
    myMidlet.lastCanvas.clear();

myMidlet.lastCanvas.put(new String("Form"), this);

And in the startApp() :

public void startApp() {
        VKBImplementationFactory.init();
        Display.init(this);
        if (lastForm != null)
            lastForm.showBack();
        else if (!lastCanvas.isEmpty())
        {
            javax.microedition.lcdui.Display.getDisplay(this).setCurrent((Canvas)lastCanvas.get(new String("Form")));
        }
        else
            new MainForm(this).show();
    }

I think this approach of using a HashTable will work even for any lcdui Form.

pheromix
  • 18,213
  • 29
  • 88
  • 158
  • if you replace form with displayable it will cover canvas as well: `public static Displayable lastDisplayable = null; //...` - assuming that `showBack` and `show` methods are applicable to Displayable – gnat Dec 20 '11 at 09:22
  • unfortunately these methods are only relevant to LWUIT. See my answer edit for the canvas , perhaps the `lcdui` Form can also be applied to the new method. – pheromix Dec 20 '11 at 10:37
1

In LWUIT, I use this

import com.sun.lwuit.Display;
......
......
......

public void startApp() {
    if (Display.isInitialized()) {
        if (Display.getInstance().isMinimized()) {
            Display.getInstance().getCurrent().showBack();
        }
    } else {
        //your normal initialization code.
    }
}
Akintayo Olusegun
  • 917
  • 1
  • 10
  • 20