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 ?
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.