One simple way (which may not be very elegant, depending on how you have written your midlet): When you create your canvas, do it something like this:
in your Midlet, pass a reference to the Midlet itself to your Canvas constructor:
MyCanvas theCanvas = new MyCanvas(this, ...);
in the Canvas constructor, save the Midlet reference:
class MyCanvas extends Canvas implements CommandListener {
MyMidlet theMidlet;
public MyCanvas(MyMidlet m, ...) {
this.theMidlet = m;
...
}
...
}
Then, when you want to close the midlet from keyPressed in MyCanvas,
just call
theMidlet.destroyApp()
Peter