Back Button Detection is a nightmare!

I’ve seen some good advice about back button detection, such as making sure dialogs are closed, etc. And I’m not a beginner at all. But my channel has major inconsistencies about when the back button events are captured in event loops. ANY advice about this would be appreciated. Here’s my example:

I open an “roGridScreen” and wait loop as usual (code is condensed for brevity):

port=CreateObject("roMessagePort")
screen = CreateObject("roGridScreen")
screen.Show()
while true
  msg = wait(0, port)
  if msg <> invalid AND msg.isScreenClosed() then
    print "back button on Main Grid DETECTED!"
    return ""
  end if
  '''''more logic that ultimately opens a second grid...
  returnState = ShowSecondGrid()
  '''''more logic to handle returnState
end while

What I find baffling is that the back button will not work initially. But if I open the second grid, it will respond to “back” and then the primary grid ALSO responds to back, i.e. msg.isScreenClosed()

Any ideas what I’m not catching?