Exiting a MIDlet (newbie)
Hi,
I'm writing a MIDlet that consists of two classes. One of the classes extends the MIDlet class and contains tha methods startApp(), destroyApp() and pauseApp(). The other class is a class which extends the Form class and is used to display a GUI.
In the first class I only get the Display object and set the display to show the second class. In the second class i have an exit-command I wish to use.
How do I call the destroyApp() method from the first class? Or is there any other way to exit a MIDlet?
Thanks in advance
Martijn
[580 byte] By [
marty2081] at [2007-9-26 14:44:51]

Hi Martijn,
Oops! Let's try that again, but this time without pressing TAB and RETURN :-)
You have two options. One would be to pass a reference to the MIDlet through to the second class, but that's not very pretty. A better way to do it is as follows:
1) Implement the CommandListener interface (and it's commandAction method), eg:
public class MyMID extends MIDlet implements CommandListener
{
.
.
.
public void commandAction(Command c, Displayable d)
{
if (c.getCommandType() == Command.EXIT)
{
destroyApp(true);
notifyDestroyed();
}
}
}
2) Make sure that the Command you create for the "Exit" is defined with the Command.EXIT type.
3) When you create the other class, set the command listener to "this", eg.
.
.
public MyMID()
{
.
.
MyForm myForm = new MyForm(...);
myForm.setCommandListener(this);
}
That should do it :-)
Thanx.
Jim.