When we start developing with Samsung smart TV, we will be having a single page app that displays various components. The user may be interacting with a few components and few of them change during the process like a component getting updated with new content, being hidden or shown etc. The above flow remains ideal for smaller applications. As the application logic and size tends to get bigger, the developer may need to include more views or pages according to the application functionality. This article will be presenting two of the commonly used ways to include more views in a smart TV application.
Including more div blocks
The most commonly used method that can be used to increase the number of pages in an application is by including more div blocks based on the application requirements. The programmer can then show or hide the div elements based on the user actions.
Pros and Cons
The user remote key handlers will work by default for all pages. The developer do not have to care about this even after showing and hiding a few divs. Since the master page remains unchanged, the remote key handler also remains unchanged. In this approach the user has to manually write custom logic to show and hide the corresponding divs based on the application requirements. This amounts to considerable amount of coding for page change.
Including more pages
Including more div blocks will be ok for small to medium range applications. When the applications go beyond that, creating individual pages seems to be a better option. The user do not have to manage all the application views in a single page and writing custom show/hide logic to manage them. Instead the user can do simple redirects to the individual pages based on user actions.
Pros and Cons
Here once the other page loads, the user has to reattach the remote key event handler logic once again. In order to avoid this caveat, the user can either write the remote key handling logic on a common file and import them on each pages, or else the user can combine any template engine and can have the remote key handling logic in a master page and can load the corresponding individual pages inside the master page, so that the developer do not have to worry about loading the key handling logic on each individual page load.
The following two methods will help the user in managing multiple pages on a smart TV application. The developer can choose any of the above existing methods based on his personal preference. Performance wise there are no major differences between the above two approaches. There are further more approaches that the developer can adopt to implement multi pages concept in smart TV applications.