1

Is there a way to trigger a roku back action via BrightScript ?

I want to pop the current screen off the navigation stack, and show the previous screen.

I need this for a couple reason :

1.) A back button will be present on screen, that the user can navigate to and press. Pressing this button should trigger a back action similar to a pressing the back button on the remote. (Think of a browsers window.history.back())

2.) I want to trigger this back action when certain callback events are called.

I currently use the following task to navigate :

function init()
    ? "[NavigationTask] init()"
    m.top.functionName = "gotoScreen"
end function

sub gotoScreen()
    if m.top.sceneName <> invalid then
        handleNav(m.top.sceneName)
    else
        print "[NavigationTask] sceneName not specified"
    end if
end sub

sub handleNav(sceneName as String)
    print "[NavigationTask] handleNav"

    screen = CreateObject("roSGScreen")
    m.port = createObject("roMessagePort")
    screen.SetMessagePort(m.port)

    if screen <> invalid
        scene = screen.CreateScene(sceneName)
        screen.Show()

        while(true)
            msg = wait(0, m.port)
            msgType = type(msg)
            print "[NavigationTask] msg : "; msgType" scene="sceneName 
            if msgType = "roSGScreenEvent"
                if msg.isScreenClosed() then return
            end if
        end while
    else 
        print "[NavigationTask] Invalid roSGScreen"
    end if   
end sub

Task is called like so :

   m.NavigationTask   = createObject("roSGNode","NavigationTask")
   m.NavigationTask.sceneName = videoScreen()
   m.NavigationTask.control  ="RUN"
Fabii
  • 3,820
  • 14
  • 51
  • 92
  • Why not use something similar to a toggle function for the visibility? Do you plan on using the same task and contentNode? – norcal johnny Jun 15 '18 at 04:17

1 Answers1

1

I wouldn't recomend handling navigation in a task thread because of Thread Rendezvous, and also you could just have one roSGScreen and one Scene and have Groups/Rectangles act as your app "screens". This would be a way more performant solution.

But anyways, back to your question, you can simulate a back press programmatically by using the External Control API.

ecpRequest = CreateObject("roUrlTransfer")
url = "http://" + roku_ip + ":8060/keypress/back"
ecpRequest.setURL(url)
ecpRequest.postFromString("")

You can obtain the roku ip address from roDeviceInfo.

Alejandro Cotilla
  • 2,501
  • 1
  • 20
  • 35
  • If I'm not mistaken, instead of using the ip address, you can just replace it w/ localhost: `http://localhost:8060/keypress/back` – mco Sep 07 '18 at 21:17
  • Apps are now being denied for this: "The use of ECP from within a channel is now prohibited" – Ken Roy Dec 18 '22 at 16:40