This topic describes multitasking, which allows you to save the application state when the user launches another application or SSSP channel, and restore it when the application is resumed. You can also monitor for changes in the visibility of your application.
When the user switches from your application to another application or SSSP channel, JavaScript execution is paused, and your application must save its current state to RAM and hide in the background. The application state is recovered when the application is resumed.
The following table lists the Samsung Signage models that support multitasking. Multitasking is also supported on the TV emulator since Tizen TV Extension 2.1.2.
Model Year | Model |
---|---|
2018 | All models, except below 18TV_STANDARD(7300) |
2017 | All models |
2016 | All models |
2015 | All models, except below 15_CLIENTDEV |
Note
To be published on SSSP, your application must handle multitasking appropriately.
A running application can be hidden based on the application logic, or through user interaction:
To be able to launch other applications, the application has to request permission by adding the following privilege to the "config.xml" file:
<tizen:privilege name='http://tizen.org/privilege/application.launch'/>
You can launch another application in 2 ways:
Calling the launch()
method:
tizen.application.launch(...);
Calling the launchAppControl()
method:
tizen.application.launchAppControl(...);
To hide the current application, call the hide()
method:
tizen.application.getCurrentApplication().hide();
To monitor the visibility state of your application, create a listener for the visibilitychange
event. The listener is notified each time your application is hidden or resumed, for example due to user interaction.
document.addEventListener('visibilitychange', function() {
if (document.hidden) {
// Behavior when application is hidden
} else {
// Behavior when application is resumed
}
});
Note
The
visibilitychange
event also fires when the application exits.
Some special scenarios can occur during multitasking. You must pay attention to these and ensure that your application responds appropriately.
During media playback
When the application is hidden during media playback, implement the same behavior as clicking the "Return" key during playback.
document.addEventListener('visibilitychange', function() {
if (document.hidden) {
// Same behavior as "Return" key click
// For example, stop playback and return to previous page
} else {
// Behavior when application is resumed
}
});
Checking network status
The network connection status can change while your application is hidden, preventing the application from functioning properly when it is resumed.
To check for network connectivity when your application resumes:
document.addEventListener('visibilitychange', function() {
if (document.hidden) {
...
}
else {
var gatewayStatus = webapis.network.isConnectedToGateway();
if (!gatewayStatus) {
// Behavior when the network is disconnected
}
}
});
If the network is disconnected, you must stop jobs requiring a network connection, such as network media playback and server request sending. Return the user to the previous page, inform them of the disconnected status using a popup, and monitor for network reconnection. For more information, see Checking Network Status.
Handling expired data
If an application is hidden for a long time, the stored runtime data can become invalid because of the service's security policy. You must check whether these data are still valid when the application is resumed. The following are examples of situations where you need to handle expired data:
Calculating time
Be careful when using the time()
method. When an application is in the hidden state, JavaScript execution is paused, potentially affecting time calculations: