scmad chapter03

23
By Marcel Caraciolo http://mobideia.blogspot.com Chapter 03 – MIDP and MIDlets SCMAD Certification 45mm 61mm

Upload: marcel-caraciolo

Post on 14-Jan-2015

1.250 views

Category:

Business


0 download

DESCRIPTION

SCMAD Review - Chapter 03 - Only for studies purposes

TRANSCRIPT

Page 1: Scmad Chapter03

By Marcel Caraciolo

http://mobideia.blogspot.com

Chapter 03 – MIDP and MIDlets

SCMAD Certification 45mm

61m

m

Page 2: Scmad Chapter03

Agenda

• Introduction to MIDP• MIDP – API’s• MIDlets and MIDlets Suites

Page 3: Scmad Chapter03

MIDP: Mobile Information Device Profile

•Depends on CLDC•Designed for mobile phones•Devices must have:•Screen (either mono, gray scale or color)• Keyboard or touchscreen• Network (limited)• Sound (rudimentary)

Page 4: Scmad Chapter03

MIDP – API’S

•Provides API’s for:• Application life cycle and installation management• User interface• 2D games• Multimedia• Persistence• Networking (HTTP 1.1 and HTTPS required)• Notifications via alarm and network• Security: Permissions and application signing• Timers

Page 5: Scmad Chapter03

MIDP – MIDlet Suites

•MIDP applications are packaged as MIDlet Suites. A suite is composed of: • JAR file with one or more MIDlets. ALL the classes that the application depends on (the application can not depend on classes from other JAR) and a Manifest.mf with this Suite’s metadata.• JAD descriptor file (not required) with Suite’s metadata (JAD is not packaged inside the JAR).• Samples: /etc/HelloWorld.jad, /etc/Manifest.mf

Page 6: Scmad Chapter03

MIDP – Manifest.mf

Page 7: Scmad Chapter03

MIDP – Application descriptor (.jad)

Page 8: Scmad Chapter03

MIDP – MIDlet Suites

•The application life cycle is controlled by the device. You will not write a “publicstaticvoidmain” method on a MIDlet, and calls to System.exit() throw a SecurityException.

• All the classes from a Suite are executed on the same VM and share resources (e.g. a static getInstance() singleton is shared between all the objects in the suite).

Page 9: Scmad Chapter03

MIDP – MIDlet Suites

Page 10: Scmad Chapter03

MIDP – MIDlet Suites

Page 11: Scmad Chapter03

MIDP – MIDlet Suites - Review

Page 12: Scmad Chapter03

MIDP - MIDlets

• Control the java application life cycle• Extend the javax.microedition.midlet.MIDlet• Sample: studyguide.cap03.HelloWorldMIDlet• You must code a constructor and three methods:• startApp• pauseApp• destroyApp

• Methods shall execute quickly• Initializations shall be done on the constructor• MIDlet class must have a no-args constructor.

Page 13: Scmad Chapter03

MIDP - startApp()

• Called when the application is started or re-activated • May throw MIDletStateChangeException, signalling errors when the application was being activated (Temporary error. User may try again later) • Define a screen that will be shown at initializations and re- activations.

Page 14: Scmad Chapter03

MIDP - pauseApp()

• Called by the device to signal the application will be put on hold (e.g. when the device receives an incoming call).• Applications shall release all the resources that will not be in use while the application is paused.

Page 15: Scmad Chapter03

MIDP - destroyApp(unconditional)

• Notifies that the application is going to be finished. This MIDlet’s instance will not be reused. If the application is started again, a new object will be created. • If “unconditional “is false, the method may throw a MIDletStateChangeException, so the application remains running. This can be used, for instance, when the application wants to confirm that the modified data may be lost. If it’s true, the exception shall not be thrown and the application will be finished.• May be called by the MIDlet itself before asking it’s termination.

Page 16: Scmad Chapter03

MIDP - MIDlet life cycle

Page 17: Scmad Chapter03

MIDP - Graphic user interface model

• javax.microedition.lcdui.Display•setCurrent: Defines the “javax.microedition.lcdui.Displayable” to be shown.• Instance is found by calling Display.getDisplay(midlet) and it is valid through all the MIDlet’s life.

Page 18: Scmad Chapter03

MIDP - Super Class methods

•notifyDestroyed(), notifyPaused(), resumeRequest():• Called by the MIDlet to indicate that the application wishes to change its state, to finalize, pause o re-start the execution (an example of re-initialization request is a thread left running on the background requesting to put the application on foreground again).

•MIDlet.getAppProperty(key):• Returns the value of an application property• Properties are defined on the JAD or manifest file• Applications may create its own properties, as long as they don’t start with “MIDlet-” or “MicroEdition-”• Shall not be confused with System.getProperty(), which returns a system property from the device (e.g. hostname, supported OP’s, phone numbers).

Page 19: Scmad Chapter03

MIDP - Super Class methods

Page 20: Scmad Chapter03

MIDP - Mandatory Attributes

Page 21: Scmad Chapter03

MIDP - Optional Attributes

Page 22: Scmad Chapter03

Future Work

• Next Chapter:

• MIDP -User Interface • API’s : High level, Low level, game• Displayable• Command• CommandListener• Ticker• Classes

Page 23: Scmad Chapter03

References

• ALVES F. Eduardo. SCMAD Study Guide, 27/04/2008.

• JAKL Andreas, Java Platform, Micro Edition Part 01 slides, 12/2007.

• Sun Certification Mobile Application Developer Website: [http://www.sun.com/training/certification/java/scmad.xml].