Java Reference
In-Depth Information
Destroyed : When the application manager wants to shut down the Xlet, it invokes
the Xlet's destroyXlet method, which must terminate the Xlet's execution. The Xlet
is now in the destroyed state, awaiting garbage collection by the runtime.
It's important to remember that an Xlet can move from the paused state straight to
the destroyed state and that it may repeatedly reenter the active and paused states
throughout its life. It's important to remember these two other things as well:
Don't call System.exit : Yours may not be the only Xlet running, and you don't
want to tear down the Java runtime. Use the XletContext object available to your
Xlet (discussed later in this chapter) instead to signal when your application
wants to close.
Free everything you can when paused and when exiting to help the garbage
collector : This is especially important for things such as remote communications
interfaces, files, and the graphics context. The application should always be able to
clean up after itself.
An interesting difference between the Xlet life cycle and the MIDlet life cycle is
that an Xlet can throw an exception, XletStateChangeException , if it wants to ignore the
requested state change. For example, an Xlet that fails to initialize can throw this
exception to keep from starting, or an Xlet that is about to be destroyed can throw this
exception to keep from being shut down by the application management system.
Extending the Xlet Interface
An Xlet must provide five methods:
A constructor : This is generally empty.
initXlet : This method takes an XletContext object and initializes the Xlet.
startXlet : The runtime invokes this method as the Xlet enters the active state.
This method must do whatever's necessary to start the Xlet's active execution.
pauseXlet : This method must release unnecessary resources and indicate that the
Xlet is in the paused state.
destroyXlet : This method must release all resources as the Xlet enters the
destroyed state and awaits garbage collection.
Listing 9-1 shows the simplest of Xlets.
 
Search WWH ::




Custom Search