08 Midlet Basic

1,354 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,354
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
53
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

08 Midlet Basic

  1. 1. MIDlet Basic Cornelius Koo – 2005 cornelius.mellino@gmail.com
  2. 2. 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.
  3. 3. MIDlet Lifecycle
  4. 4. 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.
  5. 5. Active• Active: The MIDlet is running.
  6. 6. Destroyed• Destroyed: The MIDlet has released any resources it required, and has been shut down by the application manager.
  7. 7. 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 {}}
  8. 8. startApp()protected void startApp() throws MIDletStateChangeException {}Called by application manager to startthe MIDlet.
  9. 9. pauseApp()protected void pauseApp() {}Called by application manager beforepausing the MIDlet.
  10. 10. destroyApp() protected void destroyApp(boolean arg0) throws MIDletStateChangeException {}Called by application manager to prior toshutdown.
  11. 11. javax.microedition.midlet.MIDlet
  12. 12. 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.
  13. 13. Warning !• When paused or destroyed, MIDlet should release as many resources as possible.
  14. 14. 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.
  15. 15. getAppProperty()• When needed to query MIDlet attributes, use getAppProperty().
  16. 16. Monitoring MIDlet Transition
  17. 17. 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”); }}
  18. 18. MIDletStateChangeException Thrown when error occur on state changes
  19. 19. Example MIDlet : TestException.java
  20. 20. 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.

×