We get our hands on J2ME, where we create our first MIDlet program. Let's look at the following code and I'll explain some fundamentals of MIDlet.
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class HelloMIDlet extends MIDlet {
public void startApp() {
System.out.println("Hello World");
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
As u can see, A MIDlet's main class extends the
javax.microedition.midlet.MIDlet
. It defines three life-cycle notification methods: startApp()
, pauseApp()
, and destroyApp()
.
The stuff within the startApp() method will be executed when the application is launched by the user. Here, we have a simple println statement.
Now into the lifecycle of a MIDlet. When the MIDlet object is made by calling its constructor, the application is said to be in thePaused state. We move the application to Active state by calling the startApp() method. From the Active state, we can take the application back to Paused state by calling the pauseApp() method. The thing to remember here is that startApp() and pauseApp() can be called multiple times in an application's life time. Lastly when u want to terminate the application, u calls the destroyApp() method. destroyApp() accepts a boolean parameter and if it is true, the MIDlet quit, no matter what it is currently doing. However if this is false, the application can survive termination by throwing a MIDletStateChangeException. If any runtime exception occurs within the destroyApp() method, it is ignored and the application is terminated immediately.
Tutorial here.
No comments:
Post a Comment