08 midlet basic

20
MIDlet Basic Cornelius Koo 2005 [email protected]

Upload: corneliuskoo

Post on 22-Apr-2015

1.366 views

Category:

Documents


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: 08 Midlet Basic

MIDlet Basic

Cornelius Koo – [email protected]

Page 2: 08 Midlet Basic

MIDlet

• MIDlet is an application that is built upon

the MIDlet class.

• MIDlet can communicate with Application

Manager in two-way direction.

Example: Application Manager can pause a MIDlet, while MIDlet

can make a request to be paused by Application Manager.

Page 3: 08 Midlet Basic

MIDlet Lifecycle

Page 4: 08 Midlet Basic

Pause

• Paused: A MIDlet is placed in the paused

state after the constructor has been called,

but prior to being started by the application

manager. Once the MIDlet had been

started, it may alternate between the

Paused and Active states many times

during its lifecycle.

Page 5: 08 Midlet Basic

Active

• Active: The MIDlet is running.

Page 6: 08 Midlet Basic

Destroyed

• Destroyed: The MIDlet has released any

resources it required, and has been shut

down by the application manager.

Page 7: 08 Midlet Basic

import javax.microedition.midlet.MIDlet;

public class HelloWorld extends MIDlet {

public HelloWorld() {}

protected void startApp() throws

MIDletStateChangeException {}

protected void pauseApp() {}

protected void destroyApp(boolean arg0) throws

MIDletStateChangeException {}

}

Page 8: 08 Midlet Basic

startApp()

protected void startApp() throws

MIDletStateChangeException {}

Called by application manager to start

the MIDlet.

Page 9: 08 Midlet Basic

pauseApp()

protected void pauseApp()

{}

Called by application manager before

pausing the MIDlet.

Page 10: 08 Midlet Basic

destroyApp()

protected void

destroyApp(boolean arg0) throws

MIDletStateChangeException {}

Called by application manager to prior to

shutdown.

Page 11: 08 Midlet Basic

javax.microedition.midlet.MIDlet

Page 12: 08 Midlet Basic

Warning !

• Don’t leave the code that persist through

MIDlet lifecycle or code that runs just once

time in the startApp() method because it’ll

be invoked by application manager many

times.

Page 13: 08 Midlet Basic

Warning !

• When paused or destroyed, MIDlet should

release as many resources as possible.

Page 14: 08 Midlet Basic

notifyDestroyed()

• MIDlet signals application manager that it’ll

be shutted down.

• Sequence :

- User request to exit

- destroyApp() – releasing resources

- notifyDestroyed() – tell app. manager it’s

safe to shutdown the MIDlet.

Page 15: 08 Midlet Basic

getAppProperty()

• When needed to query MIDlet attributes,

use getAppProperty().

Page 16: 08 Midlet Basic

Monitoring MIDlet

Transition

Page 17: 08 Midlet Basic

import javax.microedition.midlet.MIDlet;

public class StateTransition extends MIDlet {

public StateTransition() {

System.out.println(“constructor”);

}

protected void startApp() throws

MIDletStateChangeException {

System.out.println(“start”);

}

protected void pauseApp() {

System.out.println(“pause”);

}

protected void destroyApp(boolean arg0) throws

MIDletStateChangeException {

System.out.println(“destroy”);

}

}

Page 18: 08 Midlet Basic

MIDletStateChangeException

Thrown when error occur on state changes

Page 19: 08 Midlet Basic

Example MIDlet : TestException.java

Page 20: 08 Midlet Basic

Reference

• Core J2ME Technology and MIDP. John

W. Muchow. Prentice Hall PTR, 2002.

• Enterprise J2ME: Developing Mobile

Java Applications. Michael Juntao Yuan.

Prentice Hall PTR, 2003.

• J2ME in A Nutshell. Kim Topley. Oreilly,

2002.