Image canvas Back key issue

In my stack there are 3 screen:

  1. baseScreen
    2)middleScreen
  2. TopScreen

when i am back from 3) TopScreen to 2)middleScreen it comes in 1)base. like
3) Top->1) base

for this when i call for 3) Top from 2)middle i code here:> m.baseScreen.close()

TopScreen()

return -1
and working fine.

But flow should be:
3) Top->2)middle->1) base
if i do it screen holds on 3) Top.
for this code here:

TopScreen()

// not returning from here
But screen holds on 3) TopScreen not coming back from here.

Thanks in advance.
please share your views.

If you are using a single roimagecanvas for all three screens, then you’ll need to manually track what to draw - keeping one ‘facade’ screen open first until you want the roku to exit the app.
If you leave the previous roimagecanavas open, and create a new one on top for the middle, and a new one for the third, the back button will close the one you’re looking at, revealing the previously drawn screen underneath.

thanks destruk for reply.
Actually i am taking different screen for each layer.

                  Function onOKSelect()
                                   chooseM()
                           end function
                            function chooseM()                                             'middle screen
                                     m.chooseMscreen = createObject("roImageCanvas")
                                                 if(key = "Ok")
                                                     'screen is roImagecanvas
                                                     'm.chooseMscreen.close()
						          displayMScreen()
						
						       'return -1
                                                   end if
                                end function
                           Function displayMScreen()                                      'top screen
                                      
                                   'here is roScreen (or) roImagecanvas
                                    codesNooverlay = bslUniversalControlEventCodes()	
		
			            msgNooverlay=wait(0, m.msgportNooverlay)
                                       If msgNooverlay.GetInt() = codesNooverlay.BUTTON_BACK_PRESSED 
		  			    m.screen.Clear(&hffffff00)
					   			
				         End If

                             end function

when i open commented line in function chooseM() it work fine when i back from top screen but problem is that showing screen is base screen(Top screen → Base screen) not holding on middle screen b/c here is m.chooseMscreen.close() and return -1. but when i comment these lines screen holds on top screen and not remove(means not coming back from top).

By default, an empty or undefined layer is fully transparent.
When creating an roimagecanvas - the first screen will not have anything below it, so it works fine without specifically declaring the background to be opaque.
On subsequent screens, they are acting as overlays with transparent backgrounds, so you’ll need to set the base transparency or the prior screens will show through.
screen.SetLayer(0,{Color:“#FF000000”,CompositionMode:“Source”}) 'Black opaque background

Try out the following code – this isn’t optimized but it’s easy to troubleshoot to see what’s going on to do it as longhand.


Sub Main()
	canvas=CreateObject("roImageCanvas") 'create facade screen
'note - this facade screen is fully transparent with nothing in it, existing simply so the app doesn't prematurely exit
	canvas.Show() 'display the facade
	
	ShowScreen1() 'Biiiird....GO!
End Sub

Sub ShowScreen1()
	port=CreateObject("roMessagePort") 'create a new local message port
	screen=CreateObject("roImageCanvas") 'canvas for local screen
	screen.SetMessagePort(port) 'set local port to local screen
	canvasItems=[
	{
		Text:"1 - press down for next screen, up or back to quit"
		TextAttrs:{Color:"#FFCCCCCC", Font:"Medium",
		HAlign:"HCenter", VAlign:"VCenter",
		Direction:"LeftToRight"}
		TargetRect:{x:390,y:357,w:500,h:60}
	}
	]
	screen.SetLayer(0,{Color:"#FF000000",CompositionMode:"Source"}) 'Black opaque background
	screen.SetLayer(1,canvasItems)
	screen.show() 'display the screen
	
	While TRUE
		msg=Wait(0,port)
		If type(msg)="roImageCanvasEvent"
			If msg.isScreenClosed()
				Exit While
			Else If msg.isRemoteKeyPressed()
				Print msg.GetMessage()
				ButtonNum=msg.GetIndex()
				Print"Button Pressed msg: ";ButtonNum
				If ButtonNum=2 Or ButtonNum=0 Exit While 'UP PRESSED OR BACK PRESSED
				If ButtonNum=3 ShowScreen2() 'DOWN PRESSED
			End If
		End If
	End While
End Sub

Sub ShowScreen2()
	port=CreateObject("roMessagePort") 'create a new local message port
	screen=CreateObject("roImageCanvas") 'canvas for local screen
	screen.SetMessagePort(port) 'set local port to local screen
	canvasItems=[
	{
		Text:"2 - press down for next screen, up or back for previous screen"
		TextAttrs:{Color:"#FFCCCCCC", Font:"Medium",
		HAlign:"HCenter", VAlign:"VCenter",
		Direction:"LeftToRight"}
		TargetRect:{x:390,y:357,w:500,h:60}
	}
	]
	screen.SetLayer(0,{Color:"#FF000000",CompositionMode:"Source"}) 'Black opaque background
	screen.SetLayer(1,canvasItems)
	screen.show() 'display the screen
	
	While TRUE
		msg=Wait(0,port)
		If type(msg)="roImageCanvasEvent"
			If msg.isScreenClosed()
				Exit While
			Else If msg.isRemoteKeyPressed()
				Print msg.GetMessage()
				ButtonNum=msg.GetIndex()
				Print"Button Pressed msg: ";ButtonNum
				If ButtonNum=2 Or ButtonNum=0 Exit While 'UP PRESSED OR BACK PRESSED
				If ButtonNum=3 ShowScreen3() 'DOWN PRESSED
			End If
		End If
	End While
End Sub

Sub ShowScreen3()
	port=CreateObject("roMessagePort") 'create a new local message port
	screen=CreateObject("roImageCanvas") 'canvas for local screen
	screen.SetMessagePort(port) 'set local port to local screen
	canvasItems=[
	{
		Text:"3 - press up or back for previous screen"
		TextAttrs:{Color:"#FFCCCCCC", Font:"Medium",
		HAlign:"HCenter", VAlign:"VCenter",
		Direction:"LeftToRight"}
		TargetRect:{x:390,y:357,w:500,h:60}
	}
	]
	screen.SetLayer(0,{Color:"#FF000000",CompositionMode:"Source"}) 'Black opaque background
	screen.SetLayer(1,canvasItems)
	screen.show() 'display the screen
	
	While TRUE
		msg=Wait(0,port)
		If type(msg)="roImageCanvasEvent"
			If msg.isScreenClosed()
				Exit While
			Else If msg.isRemoteKeyPressed()
				Print msg.GetMessage()
				ButtonNum=msg.GetIndex()
				Print"Button Pressed msg: ";ButtonNum
				If ButtonNum=2 Or ButtonNum=0 Exit While 'UP PRESSED OR BACK PRESSED
			End If
		End If
	End While
End Sub

Hi destruk,
If i will do:


Sub main()
   port=CreateObject("roMessagePort") 'create a new local message port
   screen=CreateObject("roImageCanvas") 'canvas for local screen
   screen.SetMessagePort(port) 'set local port to local screen
   canvasItems=[
   {
      Text:"1 - press down for next screen, up or back to quit"
      TextAttrs:{Color:"#FFCCCCCC", Font:"Medium",
      HAlign:"HCenter", VAlign:"VCenter",
      Direction:"LeftToRight"}
      TargetRect:{x:390,y:357,w:500,h:60}
   }
   ]
   screen.SetLayer(0,{Color:"#FF000000",CompositionMode:"Source"}) 'Black opaque background
   screen.SetLayer(1,canvasItems)
   screen.show() 'display the screen
   
   While TRUE
      msg=Wait(0,port)
      If type(msg)="roImageCanvasEvent"
         If msg.isScreenClosed()
            Exit While
         Else If msg.isRemoteKeyPressed()
            Print msg.GetMessage()
            ButtonNum=msg.GetIndex()
            Print"Button Pressed msg: ";ButtonNum
            If ButtonNum=2 Or ButtonNum=0 Exit While 'UP PRESSED OR BACK PRESSED
            If ButtonNum=3 ShowScreen2() 'DOWN PRESSED
         End If
      End If
   End While
End Sub

Sub ShowScreen2()
   port=CreateObject("roMessagePort") 'create a new local message port
   screen=CreateObject("roImageCanvas") 'canvas for local screen
   screen.SetMessagePort(port) 'set local port to local screen
   canvasItems=[
   {
      Text:"2 - press down for next screen, up or back for previous screen"
      TextAttrs:{Color:"#FFCCCCCC", Font:"Medium",
      HAlign:"HCenter", VAlign:"VCenter",
      Direction:"LeftToRight"}
      TargetRect:{x:390,y:357,w:500,h:60}
   }
   ]
   screen.SetLayer(0,{Color:"#FF000000",CompositionMode:"Source"}) 'Black opaque background
   screen.SetLayer(1,canvasItems)
   screen.show() 'display the screen
   
   While TRUE
      msg=Wait(0,port)
      If type(msg)="roImageCanvasEvent"
         If msg.isScreenClosed()
            Exit While
         Else If msg.isRemoteKeyPressed()
            Print msg.GetMessage()
            ButtonNum=msg.GetIndex()
            Print"Button Pressed msg: ";ButtonNum
            If ButtonNum=2 Or ButtonNum=0 Exit While 'UP PRESSED OR BACK PRESSED
            If ButtonNum=3 ShowScreen3() 'DOWN PRESSED
         End If
      End If
   End While
End Sub

Sub ShowScreen3()
   port=CreateObject("roMessagePort") 'create a new local message port
   screen=CreateObject("roImageCanvas") 'canvas for local screen
   screen.SetMessagePort(port) 'set local port to local screen
   canvasItems=[
   {
      Text:"3 - press up or back for previous screen"
      TextAttrs:{Color:"#FFCCCCCC", Font:"Medium",
      HAlign:"HCenter", VAlign:"VCenter",
      Direction:"LeftToRight"}
      TargetRect:{x:390,y:357,w:500,h:60}
   }
   ]
   screen.SetLayer(0,{Color:"#FF000000",CompositionMode:"Source"}) 'Black opaque background
   screen.SetLayer(1,canvasItems)
   screen.show() 'display the screen
   
   While TRUE
      msg=Wait(0,port)
      If type(msg)="roImageCanvasEvent"
         If msg.isScreenClosed()
            Exit While
         Else If msg.isRemoteKeyPressed()
            Print msg.GetMessage()
            ButtonNum=msg.GetIndex()
            Print"Button Pressed msg: ";ButtonNum
            If ButtonNum=2 Or ButtonNum=0 Exit While 'UP PRESSED OR BACK PRESSED
         End If
      End If
   End While
End Sub

i am calling screen 2 direct from main() where imagecanvas screen created for screen 1 , it worked same then what is the difference between this code and your code(not create any facade screen here.)

An easy way to determine what changes are between files is “BeyondCompare” (Free) - the code I posted works for what you want it to do as I tested it here before posting.
Without the facade screen at the top, when your entire screen stack exits, the channel ends. That’s why you create the facade screen - AND by creating a black opaque facade screen it gives you a consistent black background when other screens on top are closed.

Sub Main()
canvas=CreateObject(“roImageCanvas”) 'create facade screen
'note - this facade screen is fully transparent with nothing in it, existing simply so the app doesn’t prematurely exit
canvas.Show() 'display the facade

ShowScreen1() 'Biiiird…GO!
End Sub

So change your existing code for main to be showscreen1, and use the above code for Main.
It might work on your roku - however, the letter of the operations states when you close all your screens, the roku app should immediately exit.