Programming Tutorials

java.lang.SecurityException: MIDP lifecycle does not support system exit.

By: Henry in J2ME Tutorials on 2007-09-16  

The java.lang.SecurityException: MIDP lifecycle does not support system exit error occurs when you attempt to use the System.exit() method in a Java ME MIDlet. This is because Java ME has its own lifecycle management and doesn't allow the application to terminate itself.

Instead of using System.exit(), you can gracefully terminate the application by calling destroyApp() method of MIDlet class. Here's an example:

import javax.microedition.midlet.*;

public class MyMIDlet extends MIDlet {

    public void startApp() {
        // Your application code here
    }

    public void pauseApp() {
        // Your application code here
    }

    public void destroyApp(boolean unconditional) {
        // Your application cleanup code here
        notifyDestroyed();
    }
}

In this example, the destroyApp() method is called when the application is about to be terminated. You can put your cleanup code in this method. The notifyDestroyed() method is called to notify the application management software that the MIDlet has terminated.






Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in J2ME )

Latest Articles (in J2ME)