How to go back to home screen after displaying deep linking content?

I have implemented deep linking in my channel and it all works fine. However, when I press the back button, the app exits out when I actually want it to go to the home screen instead. I think this has to do with the fact that there is no screen stack to go back to, but even when I add a screen facade, nothing works.

This is the gist of what I have:


    if ( args.ContentId <> Invalid ) and ( args.mediaType <> Invalid )      
      item = findItemById( args.ContentId )      
      if ( item <> Invalid )
        if ( args.mediaType = "episode" or args.mediaType = "movie" or args.mediaType = "short-form" or args.mediaType = "special" )
          'display springboard screen here'  
        else if ( args.mediaType = "season" )
          'display poster screen here'    
        end if 
      end if
    else 
      'showHomeScreen here'
    end if 

I would assume that I could just call the functiojn that displays the home screen after I display the respective screens during deep linking, but that doesn’t work either. Any ideas?

i presume by “home screen” you mean “my app main screen/menu” and not Roku’s Home screen.
i see no screen facade in the example above - more details in that direction may help.

“RokuNB” wrote:
i presume by “home screen” you mean “my app main screen/menu” and not Roku’s Home screen.
i see no screen facade in the example above - more details in that direction may help.
Hi!
yes, I meant my app’s main screen - in my case, the roGridScreen, that loads up after the splash screen when loading my channel the normal way, as opposed to through deep linking.
I deleted the screen facade from the example, oops. but I ended up moving all of my deep linking code into a separate functioning, and then calling the function like so:

    if ( args.ContentId <> Invalid ) and ( args.mediaType <> Invalid )      
      presentdeepLinkContent( args ) 
    else
     'show home screen here'
    end if 

and the function that holds the deep linking is:

function presentdeepLinkContent( args ) 
    if ( args.ContentId <> Invalid ) and ( args.mediaType <> Invalid )      
      item = findItemById( args.ContentId )      
      if ( item <> Invalid )
        if ( args.mediaType = "episode" or args.mediaType = "movie" or args.mediaType = "short-form" or args.mediaType = "special" )
          'display springboard screen here'  
        else if ( args.mediaType = "season" )
          'display poster screen here'    
        end if 
      end if
end function

I’m still getting the same issue as before where all the deep linking works, but no matter how I include the roGridScreen function, it doesn’t show up. Is a screen facade implementation the only way to get this to work? I’m a bit confused on how a screen facade would help me to bring a user back to the home grid screen.

The channel exits when there are no more screens left on the stack. That’s just the way it works.

So, if in your main routine you call presentdeepLinkContent then call showHomeScreen immediately after, your channel will exit after calling presentdeepLinkContent, and never get to showHomeScreen, as there are no more screens left on the stack at that point.

It could be as simple to fix as having the gridscreen created and shown without content populated, and then checking for a deeplink id - that way when it returns from the deeplink routine it then populates the existing gridscreen with content.

“destruk” wrote:
It could be as simple to fix as having the gridscreen created and shown without content populated, and then checking for a deeplink id - that way when it returns from the deeplink routine it then populates the existing gridscreen with content.
destruk,
at what point would it be best to do this? Inside my if statement that checks for the contentId and MediaType, or in the separate presentdeepLinkContent function?

When your channel runs, you need to get the launch arguments like you already are and make them available to your channel code. You have that first part working.
Next you probably want to verify the user account, log them in if necessary, and do your channel prep to prepare the home screen.
You’d want to set up your facade or display something so the channel will not close itself.
Then, at any point after that you would check for the launch parameters - which you only want to act on ONE time per channel launch.
If the parameters are for valid content, and the content is paid for, free, or able to be played, you want the channel to immediately start playing it. (We used to be able to get away with displaying a springboard screen and having the user click play, but our last submission for this was kicked back and they don’t want that anymore, now it has to immediately play if it can)
If the parameters are for valid content, and the content is NOT paid for or authorized, then it should go through the billing sequence immediately and when that completes start playing.
When the content is done playing or the user exits playing then you can display the springboard for the content, and when the user exits that display your main page of content selections.
When you are back at the main page of content, be sure to clean up any leftover variables and ignore or clear the contentID - just good practice so if the user logs out and logs back in, depending on where your branching is, it won’t loop back immediately to the original contentID.

As you are using roGridScreen for your content display, in Main you get the arguments that are passed in for deep linking,
create your facade screen
If there is a user account needed for your channel/log in required, do that next
Next create the gridscreen, download your xml or json for your content and setup, you can parse everything, call show() for the gridscreen before setting up the categories and content lists for it, and this will show some kind of text “Loading…” or something there on the gridscreen which is nice IMO.
Check your contentID arguments from the deeplink and handle it from here.
Then when the user returns from that with the back button or something else, populate the category lists for the gridscreen.

That’s how we’d do it, but you can try a few other things as you like which work just as well as this sequence.

Alternately – By moving your showhomescreen routine out of the if statement, it will be executed after your presentdeeplinkcontent runs if you have a facade created prior to ensure when presentdeeplinkcontent is done there is something to drop back to between that and showing the home screen.

  if ( args.ContentId <> Invalid ) and ( args.mediaType <> Invalid )      
      presentdeepLinkContent( args ) 
    end if 
     'show home screen here'

“destruk” wrote:
Alternately – By moving your showhomescreen routine out of the if statement, it will be executed after your presentdeeplinkcontent runs if you have a facade created prior to ensure when presentdeeplinkcontent is done there is something to drop back to between that and showing the home screen.

  if ( args.ContentId <> Invalid ) and ( args.mediaType <> Invalid )      
      presentdeepLinkContent( args ) 
    end if 
     'show home screen here'

Oh wow, okay. So some questions here:

  1. does it say somewhere in the documentation that the deep linking launch needs to immediately play the video? I did not know that! I was launching into a springboard screen, but thanks for the heads up. What if it is a mediaType of “season” and needs to go to the poster screen, will my channel still be rejected during submission?

my channel has already been published, but in order to submit a new version, I need to implement deep linking. So my app’s entire functionality and authentication is working, it’s just incorporating it with deep linking that’s causing me some trouble. :grinning_face_with_smiling_eyes:

  1. Alternatively, I created a new object inside my presentdeeplinkcontent function and was add to my screen stack, thus giving me a screen to go back to. However, the when I press the back button after viewing my deep launch content, the home screen function never gets populated on the back button, but rather displays a “Retrieving…” the whole time and I cannot figure out why.
    I think what is messing me up is the fact that my screen facade isn’t created the correct way.
function presentdeepLinkContent( args ) 
  m.screen = createObject( "roGridScreen" )
  m.screen.show()

    if ( args.ContentId <> Invalid ) and ( args.mediaType <> Invalid )      
      item = findItemById( args.ContentId )      
      if ( item <> Invalid )
        if ( args.mediaType = "episode" or args.mediaType = "movie" or args.mediaType = "short-form" or args.mediaType = "special" )
          'display springboard screen here'  
        else if ( args.mediaType = "season" )
          'display poster screen here'    
        end if 
      end if
   showHomeScreen()
end function

Thank you!

I realized I should have created the screen facade INSIDE my main function, not inside my presentDeepLinkContent function. This displays my home screen on a back button press! :grinning_face_with_smiling_eyes:

1 -
https://sdkdocs.roku.com/display/sdkdoc/Deep+Linking
For Movie, Episode, and Short Form yes -
Go to play the content directly. If the content is paywalled or the user is not authenticated you can redirect to the appropriate screen. The user should be able to play content directly after the required action is performed.
Meaning - if there isn’t a required action except to select “Play” then they want it to start playing without the user needing to select “Play”

For Season -
Go to the episodic picker screen for this season. Select the episode who’s ContentId was passed in. Do not autoplay the content.

2 - All app “Main” functions have Void return types - as that is the single function that starts the channel so it will never return anything. The Return type is to give data back to the routine that called the function, and Main() is called by the roku Home Screen when the channel launches so it can’t return anything.
What you want to do is pass the args variables for deep linking to the routine that displays your main content screen, or the poster screen, or season screen.

Rather than using presentdeepLinkContent(args) - why not simplify by sending the args to the showHomeScreen routine?

if ( args.ContentId<>Invalid ) and ( args.mediaType<>Invalid )      
 PlayID=args.ContentID
 MediaType=args.mediaType
else
 PlayID="NONE"
 MediaType="NONE"
end if 
showHomeScreen(PlayID,MediaType)

And then you would need to change your Sub showHomeScreen (if it’s a sub), or Function to something like –

Function showHomeScreen(PlayID=“NONE” As String,MediaType=“NONE” As String)

This sets the default values for the variables to “NONE” if they aren’t provided by the calling line.