Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
silentEngineer
Channel Surfer

How to create an exit dialog box that pops up when back button is clicked

How to create an exit dialog box that pops up when back button is clicked instead of back button exiting channel
' Channel entry point
sub Main()
    ShowChannelRSGScreen()
end sub

sub ShowChannelRSGScreen()
    ' The roSGScreen object is a SceneGraph canvas that displays the contents of a Scene node instance
    screen = CreateObject("roSGScreen")
    ' message port is the place where events are sent
    m.port = CreateObject("roMessagePort")
    ' sets the message port which will be used for events from the screen
    screen.SetMessagePort(m.port)
    ' every screen object must have a Scene node, or a node that derives from the Scene node
    scene = screen.CreateScene("MainScene")
    screen.Show() ' Init method in MainScene.brs is invoked

    ' event loop
    while(true)
        ' waiting for events from screen
        msg = wait(0, m.port)
        msgType = type(msg)
        if msgType = "roSGScreenEvent"
            if msg.IsScreenClosed() then return
        end if
    end while
end sub 
This is my main.brs code how to stop back button from exiting the channel, how to make back button pop up a box that asks user if they want to exit the channel, how to exit channel when exit now button is clicked on box.
0 Kudos
1 REPLY 1
lolegoogle
Newbie

Re: How to create an exit dialog box that pops up when back button is clicked

Hi!
Usually, you have a screen stack, where you can check whether the current view is the last in the stack or not. With this, you can achieve this functionality. You can use some flag for the initial screen e.g: "firstView" or smth like that, and then observe the screen stack for change. If the current view has this flag (or a similar one), and back btn has been pressed - show dialog. 

I hope you get the idea.

0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.