btpoole
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2017
09:19 AM
Close Channel
Trying to close a channel from a menu. The user clicks ok on a button (on screen) to exit the channel. Not really getting it, can somebody point me down the correct path. I have a function in the main.brs
So later on in the channel if the user wants to exit instead of hitting the home button a menu option on the screen could be picked. In order to do this I have created a task to handle the button selection but not really getting anything to work.
function home()
?"IN HOME"
screen = CreateObject("roSGScreen")
port = CreateObject("roMessagePort")
screen.setMessagePort(port)
scene =screen.CreateScene("HomeScene")
screen.show()
[size=85][font=Helvetica Neue, Helvetica, Arial, sans-serif] while (true)[/font][/size]
msg = wait(0, port)
msgType = type(msg)
?msgType
if msgType = "roSGScreenEvent"
if msg.isScreenClosed()
EXIT WHILE
[size=85][font=Helvetica Neue, Helvetica, Arial, sans-serif] end if[/font][/size]
end if
end while
end function
So later on in the channel if the user wants to exit instead of hitting the home button a menu option on the screen could be picked. In order to do this I have created a task to handle the button selection but not really getting anything to work.
<component name = "exitapp" extends = "Task" >
<interface>
<field id = "Content" type = "node" />
</interface>
<script type="text/brightscript" uri="pkg:/source/main.brs" />
<script type = "text/brightscript" >
<![CDATA[
sub init()
PRINT "IN EXIT TASK"
m.top.functionName = "exitout"
end sub
function exitout()
screen.close()
end function
]]>
</script>
</component>
19 REPLIES 19
belltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2017
09:34 AM
Re: Close Channel
This is what I use:
' Terminate the channel, exiting back to the Roku Home screen
' The first Home keypress is needed to exit the screensaver
' The second Home key press will exit to the Home screen
'
sub sendHomeKeypress()
ut = CreateObject("roUrlTransfer")
ut.SetUrl("http://localhost:8060/keypress/Home")
ut.PostFromString("")
Sleep(2500)
ut.PostFromString("")
end sub
btpoole
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2017
09:40 AM
Re: Close Channel
Excellent belltown. Just what I was looking for. Wasn't thinking about using a url transfer was trying to close the screen. Thanks again
belltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2017
09:45 AM
Re: Close Channel
btw, you don't need the Sleep() and 2nd call to PostFromString() if this is being called as a result of a user menu item selection, as there won't be a screensaver running then. In my case, I have a sleep timer which calls the routine when it expires, so there may be a screensaver active.
btpoole
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2017
09:48 AM
Re: Close Channel
Thanks for the info. I had removed it.

Komag
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2017
12:29 PM
Re: Close Channel
I may not know what I'm talking about or maybe it's different for video channels or scenegraph, but for my game, I simply RETURN from the Main() function (which is "AS VOID"), and since it's over, the channel exits.
When the use selects "exit game" from the menu, it sets a flag, and a line at end of my main while loop within Main() always checks for that flag, and if it sees it, RETURN.
Maybe my method is unreliable or susceptible to future software changes or something, and I should switch to using "keypress/Home" approach.
When the use selects "exit game" from the menu, it sets a flag, and a line at end of my main while loop within Main() always checks for that flag, and if it sees it, RETURN.
Maybe my method is unreliable or susceptible to future software changes or something, and I should switch to using "keypress/Home" approach.
belltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2017
01:43 PM
Re: Close Channel
"Komag" wrote:
I may not know what I'm talking about or maybe it's different for video channels or scenegraph, but for my game, I simply RETURN from the Main() function (which is "AS VOID"), and since it's over, the channel exits.
When the use selects "exit game" from the menu, it sets a flag, and a line at end of my main while loop within Main() always checks for that flag, and if it sees it, RETURN.
Maybe my method is unreliable or susceptible to future software changes or something, and I should switch to using "keypress/Home" approach.
If only Scream Graph were that simple. Unfortunately, Main() spins up an roSGScreen, which creates a Scene to handle the UI, running in a separate thread. You might have multiple Tasks running in their own threads as well, and a screensaver. While you can theoretically call screen.Close() within Main(), you'd first need to set up a way to signal Main() from the scene that it's time to close, and even then calling Close() only closes the main thread; the screensaver (and Tasks) continue running. Furthermore, if your screensaver is running in SD mode, the Roku then switches back to HD mode (because that's what it normally does when the main thread exits), so now you have a mini-screensaver doing its thing. And if that isn't enough ... the channel is unresponsive to remote keypresses, and the only way to get back to the Home screen is to re-boot the device. It makes me want to SCREAM.
By far the most reliable way to programmatically exit a Scene Graph application, including the screensaver and all associated Tasks, is to simulate a pair of Home keypresses.
It's nothing you need to worry about if you're using the old API or 2D API.

Komag
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2017
08:29 PM
Re: Close Channel
Holy cow, I had no idea!
destruk
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2017
09:37 PM
Re: Close Channel
So you can't just use "END" in the script section of a callback? Does that leave processes running?
belltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2017
01:08 AM
Re: Close Channel
"destruk" wrote:
So you can't just use "END" in the script section of a callback? Does that leave processes running?
Putting END in a script callback function just exits the callback. It doesn't stop anything running, even the Scene it's running in - unless I misunderstand what you're saying.
I'll put together an example when I get a moment showing how tasks and screensavers keep running if you exit from Main(), locking up the device and needing a re-boot.