Midlet Lifecycle

By default Midlet is in the paused states. when the application is executed by default startApp() method will call and when close the application the destroyApp() method will be called.

Midlet Lifecycle

     

A MIDlet lifecycle have following steps...

  • startApp()
  • pauseApp()
  • destroyApp()

By default MIDlet is in the paused states. when the application is executed by default startApp() method will call and when close the application the destroyApp() method will be called. But when your constructor is not null type then it will be executed firstly. The source code of life cycle execution is as follows:

 

 

 

import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;

public class MidletLifecycle extends MIDlet{
  private Form form;
  
  private Display display;

  public MidletLifecycle(){
  System.out.println("MidletLifecycle constructure");
  }

  public void startApp(){
  form = new Form("Midlet Lifecycle");
  display = Display.getDisplay(this);
  String msg = "This is the Lifecycle of Midlet!";
  form.append(msg);
  display.setCurrent(form);
  }

  public void pauseApp(){
  System.out.println("You are in pauseApp()...");
  }

  public void destroyApp(boolean destroy){
  System.out.println("You are in destroyApp()...");
  notifyDestroyed();
  }
}

 

Fig: MIDlet Lifecycle

Output:

Download Source Code