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: 
roquoonewbie
Visitor

EnableBackButton does not work unless AddButton is used

I think there is a bug with the roMessageDialog object. Specifically, I cannot get the back button event unless I also add a button to the dialog.

I do not want to have any button on the dialog, but I do want the user to be able to press back to quit the dialog. However, in the below code, the only way I can get the event is if I include a dummy button. Can anyone confirm they see the same? Can Roku confirm this is a bug?


Function testBackButton() As Void

port = CreateObject("roMessagePort")
dialog = CreateObject("roMessageDialog")
dialog.SetMessagePort(port)
dialog.SetText("Testing Back Button")
dialog.EnableBackButton(true)
dialog.AddButton(1, "Go Back") 'This line must be present otherwise back button event never occurs
dialog.Show()

while true
dlgMsg = wait(0, port)
if type(dlgMsg) = "roMessageDialogEvent"
Dbg("EVENT RECEIVED") 'Never gets executed unless AddButton is included above
if dlgMsg.isScreenClosed() or dlgMsg.isButtonPressed()
exit while
end if
end if
end while

End Function
0 Kudos
19 REPLIES 19
TheEndless
Channel Surfer

Re: EnableBackButton does not work unless AddButton is used

If you don't want buttons, then you might want the roOneLineDialog, but I don't think it supports the back button, so moot point.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
roquoonewbie
Visitor

Re: EnableBackButton does not work unless AddButton is used

Yes, kind of a moot point. I want a title and text in the dialog, but no on screen buttons, so that is why roMessageDialog is a good fit. I didn't include the text in my example because it does not impact the resulting behavior either way.

I don't understand why the remote control back button event has any dependency at all on the presence of on-screen buttons.

Do you see the same?

I have a Roku 2.
0 Kudos
roquoonewbie
Visitor

Re: EnableBackButton does not work unless AddButton is used

I should probably describe the use case here a bit more. When the user selects a specific poster, I need to get a lot of metadata from the web before I can proceed to building the next screen. Sometimes, that can take a long time (depending on network and server conditions). So I present a "Please wait" dialog while I am getting the info.

Right now, the user is "stuck" on this dialog screen with no way to back out. I want to give them a way to cancel the request and go back to where they were.

Is there a Roku "best practice" or example around this, given that the back button does not seem to work?
0 Kudos
RokuMarkn
Visitor

Re: EnableBackButton does not work unless AddButton is used

Why not just put a "cancel" button on the dialog? That seems more discoverable by the user than Back. Especially since some users don't have a Back button on their remote.

--Mark
0 Kudos
roquoonewbie
Visitor

Re: EnableBackButton does not work unless AddButton is used

I think that is the route I have to go. Is there any sample code that demonstrates how to kick off some web requests, while listening for an event (whether that is a back button or on screen button event), and canceling the web request process to go back a screen if one of those events happen?

I am having trouble killing the web request process when I get the event.
0 Kudos
TheEndless
Channel Surfer

Re: EnableBackButton does not work unless AddButton is used

"roquoonewbie" wrote:
I think that is the route I have to go. Is there any sample code that demonstrates how to kick off some web requests, while listening for an event (whether that is a back button or on screen button event), and canceling the web request process to go back a screen if one of those events happen?

I am having trouble killing the web request process when I get the event.

I think you want to look at roUrlTransfer.AsyncGetToString and roUrlTransfer.AsyncCancel. Listen on the same port as your message dialog, and you should be good to go. Take a look at the http_get_to_string_with_timeout function in the urlUtils.brs file in the videoplayer SDK app for an example.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
roquoonewbie
Visitor

Re: EnableBackButton does not work unless AddButton is used

Here is an example of what I mean. I want to kick off the function called "doStuffThatTakesAWhile" while I show a "Please Wait" dialog. If the user cancels the request before the "stuff that takes a while" completes, I want it to stop executing that code. But when I set it up as shown below, the output I print shows that doStuffThatTakesAWhile() completes all of its logic before the event handler even gets the message that the customer clicked cancel. The odd thing is that the dialog does in fact close on the screen when I press cancel...long before the line is logged that "User canceled out of dialog".


Output:

------ Running ------
Got to beginning of doStuffThatTakesAWhile Function
This line should not get executed if user presses back in less than 10 seconds!
User canceled out of dialog



Function testBackButton() As Void

port = CreateObject("roMessagePort")
dialog = CreateObject("roMessageDialog")
dialog.SetMessagePort(port)
dialog.SetText("Please Wait")
dialog.EnableBackButton(true)
dialog.AddButton(1, "Go Back")
dialog.Show()

while true
dlgMsg = wait(10, port)
if type(dlgMsg) = "roMessageDialogEvent" then
if dlgMsg.isScreenClosed() or dlgMsg.isButtonPressed()
Dbg("User canceled out of dialog")
exit while
end if
else if dlgMsg = invalid then
doStuffThatTakesAWhile()
endif
end while

End Function

Function doStuffThatTakesAWhile() as Void
Print("Got to beginning of doStuffThatTakesAWhile Function")
sleep(10000)
Print("This line should not get executed if user presses back or cancel in less than 10 seconds!")
End Function
0 Kudos
RokuJoel
Binge Watcher

Re: EnableBackButton does not work unless AddButton is used

Don't make your "DoStuff" function separate from your dialog function. instead, integrate the "stuff" with the loop that waits for input.

- Joel
0 Kudos
roquoonewbie
Visitor

Re: EnableBackButton does not work unless AddButton is used

Why is that necessary? And how would it help? Besides being completely impractical (because the "stuff that takes a while" in my actual code calls all kinds of re-usable HTTP, URL, and XML functions), I don't see how that would change the result at all either way.

Confirmed...same result if I move the 3 lines of sample code into the event loop.


Output:

------ Running ------
Got to beginning of doStuffThatTakesAWhile Function
This line should not get executed if user presses back in less than 10 seconds!
User canceled out of dialog



while true
dlgMsg = wait(10, port)
if type(dlgMsg) = "roMessageDialogEvent" then
if dlgMsg.isScreenClosed() or dlgMsg.isButtonPressed()
Dbg("User canceled out of dialog")
exit while
end if
else if dlgMsg = invalid then
Print("Got to beginning of doStuffThatTakesAWhile Function")
sleep(10000)
Print("This line should not get executed if user presses back in less than 10 seconds!")
endif
end while
0 Kudos