Oracle® Java ME Embedded Application Management System API Guide Release 3.4 E35109-03 |
|
Previous |
Next |
This chapter discusses tasks in the AMS. A task is an application that is running, usually started using information that the programmer provides. There can be several tasks running at the same time. Use the TaskManager
, which can be obtained from the AmsFactory
class, to manage classes.
The TaskManager
interface provides several helpful methods. You can obtain a list of all tasks with the getTaskList()
method. To obtain the TaskInfo
for the application that is currently making the call, use the getCurrentTask()
method. To obtain the TaskInfo
of the task that the user is interacting with in the foreground, use the getForegroundTask()
method.
To initiate a task, call the startTask()
method. The following information must be provided:
suiteName
– Name of the suite where the task is launched from
vendorName
– Vendor of the suite
className
– Startup class
The programmer can also do this from the AppSuite
class that represents the app.
The AMS allows the programmer to assign a TaskManagerListener
that listens to any activity made by the TaskManager
using the setStatusListener()
method.
The TaskManager
interface consists of the following methods:
TaskInfo startTask(java.lang.String suiteName, java.lang.String vendorName, java.lang.String className)
This method starts a task with given parameters. It returns a task descriptor as a TaskInfo
class, which can control the task further, or null
if the task cannot start.
TaskInfo startTaskWithOptions(java.lang.String suiteName, java.lang.String vendorName, java.lang.String className, int options)
This method starts a task with given parameters and options. It returns a task descriptor as a TaskInfo
class, which can control the task further, or null
if the task cannot start. See the Javadocs documentation for more information on possible options that can be passed into this method.
TaskInfo getForegroundTask()
This method returns the task descriptor of the current foreground task, or null if there is no current foreground class.
TaskInfo[] getTaskList(boolean includeSystem)
This method returns a list of running tasks, presented as an array of TaskInfo
classes. The boolean includeSystem
parameter indicates whether system tasks should be included in the list.
TaskInfo getCurrentTask()
This method returns the TaskInfo
descriptor of the task the caller belongs to.
void setStatusListener(TaskManagerListener theListener)
This method assigns the task status update listener, using the TaskManagerListener
interface defined in "TaskManagerListener Interface".
The TaskInfo
interface describes information about any task this is currently running. A task is always in one of four states, and has a priority from 1 to 10, as shown in Table 6-1. You can also use this class to obtain the entry class of the task. Finally, the class has three constants used to report how a task has exited.
Table 6-1 Task Status Constants in the TaskInfo Interface
Name | Description |
---|---|
|
The task was destroyed and the |
|
The task has been paused. |
|
The task is currently running. |
|
The task is starting up. |
|
The minimum priority for a task. Equivalent to 1. |
|
The normal priority for a task. Equivalent to 5. |
|
The maximum priority for a task. Equivalent to 10. |
|
The task has finished its execution without any errors. |
|
The task has been terminated. |
|
The task has finished its execution with a fatal error. |
The TaskInfo
interface contains the following methods:
java.lang.String getClassName()
int getHeapUse()
This method returns the current heap usage of the task, in bytes.
LoggerInfo getLogger(String name)
This method returns the logger associated with the specified name.
Enumeration getLoggerNames()
This method returns an enumeration of all the logger names currently in use.
int getPriority()
This method returns the priority of given task, expressed as an integer between 1 and 10. A higher number indicates a higher priority. The programmer can also use the three constants shown in Table 6-1.
int getStatus()
This method returns the current status of the task, expressed as an integer constant shown in Table 6-1 above.
SuiteInfo getSuiteInfo()
This method returns suite descriptor representing the task is executing.
boolean pauseTask()
This method pauses the task. The method returns true if successful, false otherwise.
boolean resumeTask()
This method resumes the task. The method returns true if successful, false otherwise.
boolean setForegroundTask()
This method sets the current task as the foreground task. The method returns true if successful, false otherwise.
boolean setPriority(int priority)
This method changes priority for the current task. A higher priority indicates a higher priority. The method returns true if successful, false otherwise. A higher number indicates a higher priority. The programmer can also use the three constants shown in Table 6-1.
boolean stopTask()
This method stops the current task. The method returns true if successful, false otherwise.
The TaskManagerListener
interface is used to receive update information about a change in status of a particular task. It consists of two methods.
void notifyStatusUpdate(TaskInfo task, int newStatus)
This method notifies a listener about a task's new status, defined by the constants shown in Table 6-1.
void notifyTaskStopped(TaskInfo task, int exitCode)
This method notifies a listener when a task finishes its execution, providing an integer exit code as defined in the TaskInfo
class.
The LoggerInfo
interface is a named descriptor that is used to log output. It consists of three methods.
com.oracle.util.logging.Level getLevel()
This method returns the log level that has been assigned to this logger.
void setLevel(com.oracle.logging.Level level)
This method sets the log level for this logger. Only logging messages of this level or higher are recorded to the log.
String getName()
This method returns the string-based name of the LoggerInfo
descriptor.