Service Application
Service applications are Tizen native applications with no graphical user interface that run in the background. They can be very useful in performing activities (such as getting sensor data in the background) that need to run periodically or continuously, but do not require any user intervention.
Service applications can be explicitly launched by a UI application. They can also be launched conditionally.
The user can check the running service applications in the task switcher; however, no events occur if the user selects a service application from the task switcher. The main menu does not contain icons for service applications. Multiple service applications can be running simultaneously with other service and UI applications.
The following figure and table describe the service application states.
Figure: Running service applications
State | Description |
---|---|
READY | Application is launched. |
RUNNING | Application runs in the background. |
TERMINATED | Application is terminated. |
Registering Callbacks for Service Application Events
The following table lists the application state change events.
Callback | Description |
---|---|
service_app_create_cb() | Used to take necessary actions before the main event loop starts. Place the initialization code (such as setting up the dbus connection) here. |
service_app_control_cb() | Used to take necessary actions when a service call arrives from another application. |
service_app_terminate_cb() | Used to take necessary actions when the application is terminating. Release all resources, especially any allocations and shared resources, so that other running applications can fully any shared resources. |
The following table lists the system event events.
Callback | Description |
---|---|
service_app_low_memory_cb() |
Used to take necessary actions in low memory situations. Save data in the main memory to a persistent memory or storage, to avoid data loss in case the Tizen platform Low Memory Killer kills your application to get more free memory. Release any cached data in the main memory to secure more free memory. |
service_app_low_battery_cb() |
Used to take necessary actions in low battery situations. Save data in the main memory to a persistent memory or storage, to avoid data loss in case the power goes off completely. Stop heavy CPU consumption or power consumption activities to save the remaining power. |
Application Attributes
Describe your service application attributes in the manifest file. The attributes determine the application behavior. The following code example illustrates how you can define the attributes:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns="http://tizen.org/ns/packages" package="org.tizen.message" version="0.2.7" install-location="internal-only"> <label>Message</label> <description>Message Application</description> <service-application appid="org.tizen.message" exec="/usr/apps/org.tizen.message/bin/message" nodisplay="true" multiple="false" type="capp" taskmanage="false"> <icon>org.tizen.message.png</icon> <label>Message</label> </service-application> </manifest>
Pay specific attention to the following attributes:
-
auto-restart
If set to true, the application restarts whenever it terminates abnormally. If the application is running, it is launched after installing or upgrading the package.
Note This attribute is not supported in Tizen wearable devices. Since Tizen 2.4, this attribute is not supported in all Tizen devices. Because of this, the auto-restart attribute used in a lower API version package than 2.4 is ignored in the devices with the Tizen platform version 2.4 or higher. -
on-boot
If set to true, the application launches on boot time, and after installing or upgrading the package. The application does not start if this attribute is removed after updating the package.
Note This attribute is not supported in Tizen wearable devices. Since Tizen 2.4, this attribute is not supported in all Tizen devices. Because of this, the on-boot attribute used in a lower API version package than 2.4 is ignored in the devices with the Tizen platform version 2.4 or higher.
The following table defines the behaviors resulting from the attribute combinations:
auto-restart | on-boot | After normal termination | On forced close | On Reboot | After package installation | After package update |
---|---|---|---|---|---|---|
FALSE | FALSE | Not launched automatically | Not launched automatically | Not launched after reboot | Not launched | Not launched automatically |
FALSE | TRUE | Not launched automatically | Not launched automatically | Launched automatically after reboot | Launched | Launched automatically |
TRUE | FALSE | Launched automatically | Launched automatically | Not launched after reboot | Not launched | Launched automatically |
TRUE | TRUE | Launched automatically | Launched automatically | Launched automatically after reboot | Launched | Launched automatically |