The Xlet Application Model Tech Tip By Eric Giguere
In addition to supporting traditional JavaTM applications, the
JavaTM 2 Platform, Mobile Edition (J2METM) Personal Basis Profile
(PBP) also supports the Xlet application model. Eric Giguere's tech
tip "The Xlet Application Model" teaches you how to use the Xlet
application model.
Derived from the Java TVTM APIs, Xlets are applications whose
lifecycle is closely controlled and monitored by the system. They are
very similar to the MIDlets defined by the Mobile Information Device
Profile (MIDP). Xlets are also supported by the J2METM Personal
Profile, which is a superset of the PBP.
An Xlet application's entry point is always a class that has a public
no-argument constructor, and that implements the Xlet interface.
Along with the Xlet interface, the new javax.microedition.xlet package
also defines an XletContext interface and two classes,
XletStateChangeException and UnavailableContainerException.
The timing of an Xlet's creation is up to the application management
software on the device.
The single argument passed to initXlet) is an object that implements
the XletContext interface. The Xlet customarily stores a reference to
this object because the methods it exposes allow the Xlet to
communicate with the system, in order to effect state changes and to
access its environment.
Once the Xlet is in the active state, the system can pause it at any
time. When the system needs to pause the Xlet, it invokes the Xlet's
pauseXlet() method. The Xlet is then no longer active, so it should
release as many system resources as it can, to make them available to
other applications. On return from pauseXlet() the Xlet enters the
paused state. The Xlet is not suspended, however, and any background
threads it started continue to run.
The system terminates the Xlet by invoking its destroyXlet() method. If
the boolean argument to destroyXlet() is true, the termination is
unconditional: the Xlet is destroyed without any choice in the matter.
If the argument is false, the Xlet can refuse termination by throwing
an XletStateChangeException.
Usually, the system handles Xlet state transitions. As with MIDlets,
however, Xlets have ways to request state transitions explicitly. They
can invoke methods of the XletContext interface.
An Xlet can pause or terminate itself at any point by calling the
notifyPaused() or notifyDestroyed() method, respectively. The Xlet
immediately transitions to the desired state. Note that the Xlet is the
one initiating the state transition, and neither pauseXlet() nor
destroyXlet() is called, so the Xlet should perform the appropriate
cleanup before calling notifyPaused() or notifyDestroyed().
An Xlet in the paused state can request activation by calling the
resumeRequest() method. Note that immediate activation is not
guaranteed: the system controls activation and may deny the request.
When it approves activation, it invokes the Xlet's startXlet() method.
The remaining methods of the XletContext interface are used to retrieve
properties, typically during Xlet initialization.
Giguere provides a simple Xlet that displays a message, then waits for
the user to press a key before terminating itself to be used as a
template for your own Xlets. For code and additional technical
details, please see:
Customized news reports about Sun Microsystems. Just the news you need, none of what you don't. 50,000+ Members. 20,000+ Articles Published since 1998.