views:

205

answers:

2

Surprisingly terminating a midlet doesn't work in my application. Maybe it is because I'm using Threads, but destroyApp() and notifyDestroyed() are not sufficient.

Take for example the following code:

protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
    System.out.println("destroying");
    notifyDestroyed();
}
protected void startApp() throws MIDletStateChangeException {
   try {
        // init modules
        controller.initialize();
    }catch (Exception e) {
        viewer.showAlert("error in startApp() init controller");
        destroyApp(true);
    }

}

A: 

Hi, you should call 'notifyDestroyed' method to exit your application not 'destroyApp' method.

Wonil
+1  A: 

You are specifically calling notifyDestroyed() from inside startApp().

My best guess is that the handset (or emulator) you are trying this on doesn't handle it too well.

Try this instead:

  • When controller.initialize() throws an exception, display a simple Form with a single "Exit" Command and a StringItem error message.

  • Call notifyDestroyed() from a CommandListener.commandAction() callback.

As far as threads are concerned, it is up to you to have them nicely terminate when the user wants to exit your application.

Most MIDP runtimes will be able to deal with some threads not terminating nicely but leaving system resources not properly cleaned may cause problems, especially on platforms that try to never terminate the Java Virtual Machine process itself.

QuickRecipesOnSymbianOS