How to exit / end / stop j2me midlet?

Surprisingly the termination of the midlet does not work in my application. Perhaps this is because I use Threads, but destroyApp() and notifyDestroyed() not enough.

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); } 

}

+4
source share
2 answers

You specifically call notifyDestroyed() from within startApp() .

My best guess is that the handset (or emulator) that you are trying to do this does not do too well.

Try this instead:

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

  • Call notifyDestroyed() from the notifyDestroyed() callback.

As for threads, you need to stop them when the user wants to exit your application.

Most MIDP sessions will be able to handle some threads that do not stop beautifully, but system resources are not cleaned up correctly, which can cause problems, especially on platforms that never stop the Java virtual machine process itself.

+2
source

you should call the notifyDestroyed method to exit the application, not the destroyApp method.

0
source

Source: https://habr.com/ru/post/1307935/


All Articles