Home J2me Midlet Lifecycle
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Midlet Lifecycle

Advertisement
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

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 3, 2008

Related Tutorials

Ask Questions?    Discuss: Midlet Lifecycle   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Eshrath
June 3, 2013
J2me

I tired j2me example MidletLife Cycle In that 1st constructor will call but for me startapp() is callingg... where iam going wrong can you tell me... plz,...
anant mitra
May 16, 2012
error in RUN

after doing all the setting and building the program..while running the program it shows an error and it doesn't execute Exception: java.lang.classNotFoundException: TutorialMIDlet
K. Sudheer Kumar
July 14, 2012
regarding structure of writing a midlet

I am not correctly understanding how a j2m3 midlet can execute without writing main function and we are writing public before a class(midlet) what are steps involved for executing a j2me program?
DMCA.com