by Richard Marejka Welcome to the MIDlet Life-Cycle Learning Path! Here you'll find a brief introduction to the life-cycle of an application based on the Java 2 Platform, Micro Edition (J2ME), and links you can follow to articles, sample code, and specifications that will give you a solid grounding in this crucial area of J2ME-based development. The MIDlet Life-Cycle learning path is a bit different from others in format. Many simply state goals and prerequisites briefly, then provide links to the content. This one provides the basic content directly, and along the way furnishes links to other resources. This learning path will focus on source code. Why? Ultimately in a product life-cycle, someone must actually create an instantiation of a design that was based an architecture that was begotten by an idea. Business cases, designs, and architectures cannot be compiled to run on devices. Someone actually has to produce code that embodies the design, meets high standards of quality, and meets users' needs. This coding task includes crafting a build environment, managing a source base, and serving it all up in a form that allows the the developers to crank out the product in its deliverable form, on demand. Control and repeatability are key elements of software product management. So where does all this lead? Virtually all source code is layered on top of existing application progamming interfaces (APIs). How well you understand the APIs you consume, and how correctly you use them, directly affect the quality of your product. Merely reading the API specifications isn't enough. Code that reflects a deep understanding of the API, and that demonstrates correct patterns of use, both reinforce the specification and provide idioms that can be directly employed by other developers. The purpose of this learning path is to help you produce that kind of code.
IntroductionUnderstanding the MIDlet life-cycle is fundamental to creating any MIDlet. The life-cycle defines the execution states of a MIDlet – creation, start, pause, and exit – and the valid state transitions. The application management software (AMS) is the software on a device that manages the downloading and life-cycle of MIDlets. The AMS provides the runtime environment for a MIDlet. It enforces security, permissions, and execution states, and provides system classes and scheduling. JADs and JARsThe basic components of any MIDlet suite you will deliver are the Java Application Descriptor (JAD) file and the Java Archive (JAR) file. Together, these two items are the MIDlet suite.
The JAD file, as the name implies, describes a MIDlet suite.
The description includes the name of the MIDlet suite, the location and
size of the JAR file, and the configuration and profile requirements.
The file may also contain other attributes, defined by the Mobile
Information Device Profile (MIDP), by the developer, or both. Attributes
beginning with
A MIDlet suite on a device is identified by the attribute tuple
The JAR contains one or more MIDlets, specified in the JAD using the
MIDlet-n : MIDletName , [IconPathname] , ClassNamewhere:
A manifest file is located at
In addition to the Java class files and the manifest, the JAR file
may contain other resources. These may be images that the MIDlet
can load using the
The Security ModelThe J2ME security model is a scaled-down version of the J2SE model. It has been adapted to work within the contrained resources common among J2ME devices. The rules are:
The short of it is:
InstallationThere are two ways to install a MIDlet suite. The first, called direct, involves some direct connection between the device and the development platform – commonly cable, infrared, or Bluetooth link. In the case of the Nokia 6100, for example, it's a Nokia DKU-5 USB cable and the Nokia PC Suite software, which includes Nokia Application Installer. You develop the MIDlet suite, perhaps test it in an emulator, then install it using the USB cable and Nokia Application Installer. While this method is efficient for testing on your own device, it is hardly suitable for deploying an application to millions of end users. Over-the-air provisioning (OTA) makes large-scale deployment possible – even easy. A device can install a MIDlet suite from a remote server using the device's built-in browser. Simply entering the URL of the suite's JAD file into the browser address field starts the installation process. In general terms:
This description omits steps relating to signed MIDlet suites, permissions, and push-registry entries, collapsing them into the "verifies message and JAR file" step. Error handling has also been omitted to simplify presentation.
The success of the installation process depends on correct
functioning of the web server and the device's browser. Characteristics
of the network between the device and server can affect installation
too. One frequent cause of OTA failure is a size limit that network
elements impose on the size of the JAR file. Another is specifying
incorrect MIME types for JAD and JAR files. The correct MIME type for a
JAD file is RemovalHere's the easiest part: Because a MIDlet suite is a self-contained entity, deleting it is simple. Most devices allow the user to select a MIDlet suite and choose a Delete option from a menu. At this point the device likely asks for confirmation; a positive response removes the MIDlet suite, including any push-registry entries and record stores created by any MIDlet in the suite. On a Sony Ericsson T616, for instance, the deletion process looks like this:
The Quintessential First ProgramSince the days of Kernighan and Ritchie's The C Programming Language (1978), the first program most developers attempt when they begin using a new language or environment is Hello World. The C version contains only a few lines, including the specification of an I/O library, and the output is only a simple greeting, but this venerable program gives you the chance to prove much: that you can write, build, debug (if necessary), and run a program. So developers using Java technology won't be left out, the article "Wireless Development Tutorial Part I" provides a J2ME version of Hello World and instructions on building it. Execution States
When a MIDlet begins execution, the AMS first calls the
zero-argument constructor to create a new instance of the MIDlet. The
constructor typically does little or no initialization. The AMS
framework provides transitions that you can use as control points for
resource management, as you'll soon see. When the constructor returns,
the AMS places the MIDlet in the Paused state. To shift the
MIDlet to the Active state the AMS calls the
A transition from the Active state back to the Paused
state occurs whenever the AMS calls
These transition methods give you the opportunities you need to
manage resources effectively. Typically, you'll use
The only question left is: What differentiates one-time resources from other resources? There is no definitive answer, only a set of guidelines:
The MIDlet may enter the Destroyed state from either
Paused or Active, on a call to
There are a few variations on this Paused/Active/Destroyed
theme. First, a MIDlet may voluntarily enter the Paused state by
calling
There are still some open questions here, about the interactions
between the AMS and the MIDlet. These can be characterized as the
why and the when. For example, when is
Sample Source
Source code available from the Java mobility site comes in two
forms: one for online viewing and another for download. The download
version is in J2ME Wireless Toolkit application format. The following
table also supplies a reference to the article relevant to each sample.
If you're using the J2ME Wireless Toolkit, you can begin working with
the source files simply by unzipping the archive and moving the
applications into the Which brings us to the toolkit itself – the J2ME Wireless Toolkit, of course, a state-of-the-art toolbox for developing wireless applications based on MIDP. The current release at this writing, 2.2, supports CLDC 1.0 and 1.1, MIDP 1.0 and 2.0, and seven other J2ME JSRs. The toolkit allows the developer to choose the JSRs that best match the target environment, build JAD and JAR files, and run MIDlets in an emulator before deploying them on target devices. The toolkit is available for download. SummaryThis learning path has described the basics of the MIDlet runtime environment, the AMS, including its security model, available APIs, and execution-state machine. Several sample MIDlets, with related articles, are available in both online and download formats for your further education. Future learning paths will cover such topics as network and resource I/O, user interface, persistent storage (RMS), and a collection of miscellaneous subjects. 1As used in this document, the terms "Java virtual machine" or "JVM" mean a virtual machine for the Java platform. Back To Top | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||