Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Level 7

Back Button and Deep Linking

I am just getting started with deep linking and having a hard time with it. I have figured out how to set up a deep link to go to the poster page for a specific show.

The problem is that when I get to the poster page via the deep link, when the user presses the back button on their remote, no message is sent and the channel closes entirely.

If I go to the same page via normal navigation, starting on my channel home page, I can detect a message using this test:


Works totally fine other than when I skip the normal UI and deep link directly to the poster screen for a show.

Can't figure out what is going on. Prior to the poster screen loading, no other screens or dialogs are being loading.

I initialize the screen like this:

Function preShowSeasonScreen(breadA as String, breadB as String) As Object

if validateParam(breadA, "roString", "preShowSeasonScreen", true) = false and validateParam(breadA, "String", "preShowSeasonScreen", true) = false return -1
if validateParam(breadA, "roString", "preShowSeasonScreen", true) = false and validateParam(breadA, "String", "preShowSeasonScreen", true) = false return -1

screen = CreateObject("roPosterScreen")
if breadA<>invalid and breadB<>invalid then
screen.SetBreadcrumbText(breadA, breadB)
end if

return screen

End Function

Then I call the screen like this:

Function showSeasonScreen(screen As Object, SeasonDetails as Object) As Integer
print "================function showSeasonScreen======================"

if validateParam(screen, "roPosterScreen", "showSeasonScreen") = false return -1

m.curCategory = 0
m.curShow = 0
print "set category names for seasons"
'get classes for season at the current category index
classes = getContentForSeason(SeasonDetails, 0)
print "display the show screen"
print "screen is displayed"

while true
print "wait for message"
msg = wait(0, screen.GetMessagePort())
print "message received of type: " + AnyToString(type(msg))
if type(msg) = "roPosterScreenEvent" then
print "showPosterScreen | msg = "; msg.GetMessage() " | index = "; msg.GetIndex()
if msg.isListFocused() then
m.curCategory = msg.GetIndex()
m.curShow = 0
classes = getContentForSeason(SeasonDetails, m.curCategory)
print "list focused | current category = "; m.curCategory
else if msg.isListItemSelected() then
m.curShow = msg.GetIndex()
print "list item selected | current show index = "; m.curShow
contentId = classes[m.curShow].ContentId
contentType = classes[m.curShow].contentType
print "content id: " ; contentId

showName = seasonDetails[0].showName
seasonName = seasonDetails[0].seasonNames[m.curCategory]

m.curShow = displayContentDetailScreenFromSeason("", "", m.curShow, classes)
print "list item updated | new show index = "; m.curShow

else if msg.isScreenClosed() then
print "screen is closed!"
return -1
end if
end If
end while
End Function

So it the waiting part, I expect the msg.isScreenClosed() event, but it doens't happen via deep link. Using the same exact code and the normal navigation, it works.

One thing I tried is putting a screen in the stack below this (just a blank loading screen) with the thought that having nothing below my screen in the stack might be causing an issue, but that doesn't work at all.

All the navigation works totally fine, and I get the expected messages from all button clicks other than the back button. Help would be much appreciated as I'm stumped.
0 Kudos
2 Replies
Level 7

Re: Back Button and Deep Linking

As crazy as it sounds, I seem to have found a work-around to this. If I load a blank screen prior to loading my show screen, like this:

screenFacade = CreateObject("roPosterScreen")

It seems to fix the problem. Found that advise elsewhere in the forums.

The issue seems to be that the Roku quits the channel instantly when it sees nothing below the current screen in the stack, so instantly that it doesn't even send the message that you could intercept with msg.isScreenClosed() so you basically can't run any code at all.

I had actually tried loading a "blank" screen like this before:

Sub ShowWait() As Object
port = CreateObject("roMessagePort")
screen = CreateObject("roParagraphScreen")

screen.AddHeaderText(" ")
screen.AddHeaderText(" ")
screen.AddHeaderText("Processing...Please Wait...")
screen.AddHeaderText(" ")
screen.AddHeaderText(" ")
screen.AddHeaderText(" ")
Return screen
End Sub

This does not work. It causes the channel to instantly crash back to the Roku channel store (or wherever you were on Roku).

If I take the code out of the sub-routine and run it instead of calling ShowWait() it DOES work. Don't get it.
0 Kudos
Level 8

Re: Back Button and Deep Linking

Yes, it is documented in Working with Screens that the app exits when the last screen is closed. Your non-working facade example would work only if you save the returned screen in a variable in the calling function. Otherwise the screen variable becomes unreferenced when the function returns and the screen is closed.

0 Kudos