Your Digital Media Has Never Looked So Good

Topic Author
Posts: 110
Joined: Wed Jun 02, 2010 4:25 pm

Dialog and Closing App

Sun Nov 12, 2017 8:07 am

Hi, just getting started with SG, I'm old school SDK trying to catch up.  I'm trying to launch a dialog and when user clicks OK, it ends the app.  I was trying to use the "dialog example" from Roku.
So what I do is call the below sub which displays the dialog shown in XML file below.  My problem is once user clicks OK, I want to close the app.  Right now, when I click OK, nothing happens because its doing nothing but returning Boolean value.  I'm not sure what I need to call at this point to kill the app.  I tried a roUrlTransfer call but it errors out on the SetUrl property ("http://localhost:8060/keypress/Home").  I assume this type of call won't work in the onKeyEvent so do I need to return focus somehow to the screen so I can close it?
Any help would be appreciated.
sub showChannelSGScreen()
  screen = CreateObject("roSGScreen")
  m.port = CreateObject("roMessagePort")
  scene = screen.CreateScene("DialogExample")
    msg = wait(0, m.port)
    msgType = type(msg)
    if msgType = "roSGScreenEvent"
      if msg.isScreenClosed()
      end if
    end if
  end while
end sub

<component name = "DialogExample" extends = "Scene" >
  <script type = "text/brightscript" >


sub init() = "pkg:/images/rsgde_bg_hd.jpg"
end sub

    sub showdialog()
      dialog = createObject("roSGNode", "Dialog")
      dialog.backgroundUri = "pkg:/images/rsgde_dlg_bg_hd.9.png"
      dialog.title = "My title"
      dialog.optionsDialog = true
      dialog.message = "Press * To Dismiss" = dialog
    end sub

function onKeyEvent(key as String, press as Boolean) as Boolean
  if press then
    if (key = "OK") then
    return true
    end if
end if
return false
end function

Posts: 227
Joined: Wed Jul 15, 2015 8:30 am

Re: Dialog and Closing App

Mon Nov 13, 2017 8:15 am

You need to tell the source/main.brs loop to exit, here's some crude and untested code that might do the trick

while true
  msg = wait(0, m.port)
  if type(msg) = "roSGNodeEvent"
   if msg.getField() = "pleaseExitNow"
   'close the loop, kill the app
   end if
  end if
end while
Topic Author
Posts: 110
Joined: Wed Jun 02, 2010 4:25 pm

Re: Dialog and Closing App

Mon Nov 13, 2017 10:51 am

Thanks, will give it a try but I guess I have to add the node to the diaglogexample.xml file?  How do you do that?
Posts: 4
Joined: Wed May 08, 2019 11:58 am

Re: Dialog and Closing App

Tue May 21, 2019 2:28 pm

Was anyone able to accomplish this?

Who is online

Users browsing this forum: No registered users and 5 guests