top

Multitasking

Samsung Smart TV supports multitasking. This document explains how multitasking works, how to control multitasking and handling special situations in Multitasking.

Overview

Samsung TV supports multitasking for application in the following situation.

  • Launching other application over currently running application
    • by calling tizen.application.launch or tizen.application.launchAppControl method.
    • by clicking “Smart Hub” key of remote controller and run other application.
  • Calling tizen.application.getCurrentApplication().hide method.
  • Turning off TV during application running in “Samsung Instant On” mode.
    (“Samsung Instant On” : Enable TV to turn on quickly. (“Menu” > “System” > “Gerneral” > “Samsung Instant On” > “ON”))
  • Clicking “Source” key and change source.

In above all situations, application goes into hiding state, JavaScript is paused, and the current state of application is stored in RAM. The state is recovered when the application is resumed. So, if application relaunch, previous state of application is recovered.

Note

As “Apps” policy, all applications should support multitasking and should work well.
Without Multitasking support, Application cannot be released on seller site

Dependencies

Depending on the model of Samsung TV, multitasking can be supported or not.
Please refer to the following table.

Table 1. Support Model
Product Support Model
Samsung TV All of 2015 Samsung TV models onwards
Samsung TV SDK Version 2.1.2 onwards

Implementation

Launching Other Application

There are a few ways to launch other application.

You need to set the following privilege in [config.xml] to use these methods.

<tizen:privilege name='http://tizen.org/privilege/application.launch'/>

Calling hide Method

If you call the following method, application goes into hiding state.
Please refer to the Application API.

tizen.application.getCurrentApplication().hide();

visibilitychange Event Listener

By adding visibilitychange event listener, you can check whether the application is hidden and resumed.

document.addEventListener('visibilitychange', function (){
	if(document.hidden){
		//Something you want to do when an application is hidden.
	} else {
		//Something you want to do when an application is resumed.
	}
});
Note

visibilitychange event also occurs when application exits.

Special Situations

During multitasking, unexpected issues may be occured. Please refer below cases and test your application sufficiently on TV or SDK and confirm that your application works well in multitasking environment.

Playing Contents by Using AVPlay

If you use webapis.avplay for playing media contents, you should call some methods when the application is hidden and resumed. If you use video tag, you don’t have to do it.

When the application is hidden, you should call webapis.avplay.suspend to store last state of playback.
And when the application is resumed, you should call webapis.avplay.restore to restore the last state of playback.

You don’t need to call pause and play in multitasking. The suspend and the restore methods take care of playback state automatically.

  • When do not use DRM
    If there is no chance that URL or session is expired as time goes on, use this code snippet.

    document.addEventListener('visibilitychange', function() {
    	if(document.hidden){
    		webapis.avplay.suspend(); //Mandatory. If you use avplay, you should call this method.
    	} else {
    		webapis.avplay.restore();
    	}
    });
    
  • When use DRM
    You need to reset DRM session.

    document.addEventListener('visibilitychange', function() {
    	if(document.hidden){
    		webapis.avplay.suspend(); 
    	} else {
    		webapis.avplay.restore(url, resumeposition, true);
    		webapis.avplay.setDrm('', '', '');
    		webapis.avplay.prepare();
    		webapis.avplay.play();
    	}
    });
    
  • When contents URL is changed as time goes on
    Give new URL as parameter of restore method. For example, Live Channel, session may be expired or dynamic token may be added to its content URL.

    document.addEventListener('visibilitychange', function() {
    	if(document.hidden){
    		webapis.avplay.suspend(); 
    	} else {
    		webapis.avplay.restore(url, resumeposition, true);
    	}
    });
    

Getting Focus and Show Highlight

In running an application, the focus & highlight of application must be on an element such as video control bar, popup, button, etc. Because these focus and highlight should be resumed successfully, we recommend managing these when the application is hidden and resumed.

For preventing these from entangling, we recomment you to store these state when the application is hidden, and then provide the focus and highlight to the element again when the application is resumed.

Checking Network Status

While application is hidden, network may be disconnected because of unexpected issues. In this case, the application may not work when it is resumed. So, you should call the following method when application is resumed.

document.addEventListener('visibilitychange', function() {
	if(document.hidden){
	} else {
		var gatewayStatus = webapis.network.isConnectedToGateway();
		if (!gatewayStatus){
			//Something you want to do when network is disconnected.
		}
	}
});

If network is disconnected, we recommend you to stop doing current jobs like playing media contents or request something to server and return to the previous page. And it’s better to show a notice popup for the user which informs this status.

Network may be reconnected after several seconds when the application is resumed. In this case, you can utilize the following method.

webapis.network.addNetworkStateChangeListener(function (data) {
	if(data == 4){
		//Something you want to do when network is connected again.
	} else if (data == 5){
		//Something you want to do when network is disconnected.
	}
});

Every time network status is changed, this method informs you network status. Please note that this method should be called when the application initially runs, not is resumed.

Expiration of Data

If an application is hidden for a long time, the data which is stored in runtime could not be valid anymore because of the service’s security policy, so you need to check whether these values are valid when the application is resumed. Following are the expected examples of the data.

  • Login session
    Most of applications have login processes depend on these company policy. After several hours, the login session is expired and the login key is not available, In this case, the application may not work. For preventing this problem, please check the login session in your process when the application is resumed.
    If the login session is expired, please make the application to be unsigned and show a notice popup for requesting to login again.
  • Media contents with DRM(Digital Right Management)
    Media contents with DRM are expired due to DRM policy. After a long time, a content request URL is changed to a different URL. So the previous URL is not available. If an application requests the same URL after several hours, the contents cannot play.
    To prevent this situation, please check whether the URL is valid when the application is resumed. If it is expired, please stop playing media contents and return to the previous page. We will recommend you to show a notice popup for the user which informs this status.

Using time Function

As mentioned above, JavaScript is paused in hiding state. So, you should pay attention to use time function. The following is the examples.

  • Some activities in calculating a time cannot be correct. For example, we don’t recommend that the expiration deadline of data is calculated by using time functions internally. You should make to communicate to the service’s server for checking the deadline. It is recommended.
  • It may happen that popup will not close automatically after few seconds once the app is in hide state. We will recommend you to check the popup timeout.