In MIDlet program learning, the life cycle is a relatively abstract concept. In fact, the lifecycle is a simple rule that prescribes each method in the MIDlet and when it is called by the system. Here is an example code that outputs a statement inside each method, which verifies the order in which each method is invoked, depending on the output of the program, as follows:
The following is a reference fragment:
FileName: Lifecirclemidlet.java
Import javax.microedition.midlet.*;
/**
* Test the life cycle of MIDlet
*/
public class Lifecirclemidlet extends midlet{
/**
* Default Construction method
*/
Public Lifecirclemidlet () {
SYSTEM.OUT.PRINTLN ("Default construction Method");
}
/**
* Start method
*/
public void startApp () {
System.out.println ("Startapp method");
}
/**
* Suspend method
*/
public void Pauseapp () {
System.out.println ("Pauseapp method");
}
/**
* Destruction Method
* @param b
*/
public void Destroyapp (Boolean b) {
System.out.println ("Destroyapp method");
}
}
When you run the program in J2WTK, you can simulate the pause event by using the Pause and restore menu in the MIDlet menu in the browser.