Trying to mash together two (or three) examples I found, to create a dialog that will fire if you press back arrow when on the home screen (or technically the last screen in the stack array).
So what I am trying to achieve is a logic along the lines of:
-
Intercept the backarrow key (onkeyevent)
-
Display dialog for “Confirm Exit”
3 observeField “buttonSeleted” and set callback to “onButtonSelected”
- Return true to tell Roku that we handled the backarrow
Then later (buttonSelected)
- set m.top.exitApp = true (which breaks the while loop and exits the program)
I’m fairly certain step 1-4 is working, but step 5 is never called. (the print to the debug log never happens)
Here is the code:
sub showExitDialog()
m.exitDialog = createObject("roSGNode", "Dialog")
m.exitDialog.backgroundUri = "pkg:/images/dialog-background.png"
m.exitDialog.title = "Close channel"
m.exitDialog.buttons = ["Exit", "Cancel"]
m.exitDialog.optionsDialog = true
m.exitDialog.message = "Do you want to close Channel"
m.exitDialog.observeField("buttonSeleted", "onButtonSelected")
m.top.dialog = m.exitDialog
end sub
'detect selection
sub onButtonSelected()
'use the exitDialoge Button Selected field
print "Serring Exit to true"
if m.exitDialog.buttonSelected = 0 then
print "Exiting app"
m.top.exitApp = true
else
print "Doing nothing"
end if
end sub
And the code to intercept the back arrow
function onKeyEvent (key as String, press as boolean) as boolean
handled=false
if press then
if (key = "back") then
handled=true
print "You pressed back"
showExitDialog()
end if
end if
return handled
end function
Also, I stole from two different examples, where the first one is
And the second one was how to break the while loop
https://rymawby.com/brightscript/roku/Exiting-out-of-a-brightscript-scenegraph-app.html
Also, the example used observeFieldScoped, but could not find any documentation on what that does. (A bit new to brigthscript, so sorry if that is obvious)
