Java Reference
In-Depth Information
public void startApp() {
if (!started) {
// MIDlet started first time
workerThread = new WorkerThread();
started = true;
} // MIDlet brought to foreground
paused = false;
workerThread.resumeWork();
} public void pauseApp() {
// MIDlet sent to background
paused = true;
workerThread.pauseWork();
}
In reality, things might work slightly differently so Section 4.5 discusses
how to handle the state switches across different Symbian smartphones.
For now, note the importance of releasing unused resources and suspend-
ing certain operations while running in the background.
Your application should not consume resources, such as CPU, for
operations that are not necessary while in the background (e.g., ren-
dering threads) but it is still alive and running. Depending on the
core task of your application, it may be possible to fulfill some of
those tasks even when running in the background. For example, if
your application is registered to receive events, such as incoming SMS
messages or location notifications, the registration for receiving events
does not need to be removed every time the MIDlet
is sent to the
background.
To illustrate such a case, the following example implements WMA
MessageListener , which queues or displays an incoming message
according to the state of the application. If the application is in the
Paused state, then only minimal processing is done. If the application is
Active, then it should operate with full functionality enabled.
{
public void notifyIncomingMessage(MessageConnection conn)
if (paused) {
// TODO: silently add incoming message to queue, to be handled later
}
else {
// TODO: display incoming message to user or perform another action
}
}
3.5.2 Multitasking of MIDlets in the Same Suite
Let's see how two MIDlets from the same suite, both running at the same
time, can not only access the same classes in the JAR file but also invoke
methods of objects owned by the other running MIDlet. All MIDlets from
Search WWH ::




Custom Search