Multitasking

This topic describes multitasking, which allows you to save the application state when the user launches another application or TV channel, and to restore it when the application is resumed. You can also monitor for changes in the visibility of your application.


Related Info


When the user switches from your application to another application or TV 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 TV models that support multitasking. Multitasking is also supported on the TV emulator since Tizen TV Extension 2.1.2.

Year Support Model Groups
Smart TV HTV Signage
Tizen 7.0
(2023)

23TV_PREMIUM1, 23TV_PREMIUM2, 23TV_PREMIUM3, 23TV_PREMIUM4, 23TV_PREMIUM5, 23TV_STANDARD1, 23TV_BASIC1, 23TV_BASIC2, 23TV_BASIC3 - -
Tizen 6.5 (2022) 22TV_PREMIUM1, 22TV_PREMIUM2, 22TV_PREMIUM3, 22TV_STANDARD1 22TV_STANDARD1_B2B 22SIGNAGE_STANDARD
Tizen 6.0 (2021) 21TV_PREMIUM1, 21TV_PREMIUM2, 21TV_PREMIUM3 - -
Tizen 5.5 (2020) 20TV_PREMIUM, 20TV_STANDARD, 20TV_BASIC1
Tizen 5.0 (2019) 19TV_PREMIUM, 19TV_STANDARD
Tizen 4.0 (2018) 18TV_PREMIUM
Tizen 3.0 (2017) All model groups
Tizen 2.4 (2016) All model groups
Tizen 2.3 (2015) All model groups (except below 15_CLIENTDEV)

Table 1. Samsung TV model groups supporting multitasking

If you want to know more about TV Seller Office Model Groups, see device model groups.

A running application can be hidden based on the application logic, or through user interaction:

  • Based on the application logic:
  • Through user interaction:
    • The user can use the remote control to launch another application or change the input source.
    • The user can switch off the TV, if "Samsung Instant On" mode is enabled in the TV settings.

Hiding Applications

To hide the current application, call the hide() method:

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

Monitoring Visibility Changes

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
  }
});

Special Multitasking Scenarios

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, stored runtime data can become invalid because of the service's security policy. You must check whether this data is still valid when the application is resumed. The following are examples of situations where you need to handle expired data:

    • Login sessions
      Many service providers have policies where a login session expires after several hours and the user must log in again to use the service. When your application resumes, check the login session validity. If it has expired, show a logged out screen and a popup requesting to log in again.
    • Media content using digital rights management (DRM)
      For media content using DRM, the content URL can expire after some time and change to a new URL. The content cannot play using the expired URL. When your application resumes, check the content URL validity. If it has expired, return the user to the previous page and show a popup informing them of the expired status.
  • 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:

    • Do not calculate data expiration time internally. Instead, check for data expiry by communicating with the service provider's server.
    • Notification popups which close automatically after a few seconds can fail to close if the application has entered the hidden state. Implement the popup timeout carefully.