Question Using pushModalScreen() method

I have a PopUpScreen that I'm trying to have pop up in front of my main Screen class. I've been able to make the PopUpScreen pop up when needed, however it seems the main Screen class does not stop processing. I would like to pause (for lack of a better word) what is happening on the main Screen until the PopupScreen is closed (using close() ).

I have tried using UiApplication.getUiApplication().invokeAndWait and invokeLater methods. InvokeAndWait causes a RunTimeException on the pushModalScreen call, and invokeLater invokes the PopUpScreen, but allows the main Screen class to continue processing before the PopupScreen returns.

Also, do I need to use invokeAndWait() when I am trying to use the pushModalScreen call? I'm a little confused, but I thought pushModalScreen automatically paused what was going on with the calling class until the PopupScreen (or whatever screen is set by pushModalScreen) is closed.

I get a runtime exception stating that pushModalScreen was called on a non-event thread. I don't have any other threads explicitly defined in my program, so unless there's a non-event background thread trying to process this pushModalScreen call, I'm not sure why it's throwing that.

Re: Question Using pushModalScreen() method

What is the message that is thrown with the exception you get from invokeAndWait?? From where in your main Screen are you trying to push the modal screen? If it is from onDisplay() or similar methods, that may be a cause for weird issues.

You can also try a synchronized(UiApplication.getEventLock()) block. Although I have noticed on some background Threads the sync block does not work with a modal screen, yet invokeAndWait does.

I am passing "this" into the Customized Screen object because I want to refer to one of the MainAppScreen's methods from the popup screen, after OK is clicked. The PopupScreen is basically (the PopUpScreen class name is different from the actual PopupScreen class I am extending)...

Re: Question Using pushModalScreen() method

I presume this is happening at startup? You create an instance of your application, that creates an instance of your MainAppScreen, which tries to display the screen, all before the Application has indeed 'enterthedispatcher?

In this situation, your invokeLater code is the correct way to handle this.

You can't stop the initialization of your MainScreen in this way if it is the first screen in your application, because it is stopping your application 'entering the dispatcher'. If you do need the answer to the Popup before you complete the MainScreen, then I think the easiest option is to put the processing into the 'close' of the Popup Screen.

There are other options which are probably more elegant if this grates with you.

Re: Question Using pushModalScreen() method

You know what, that makes perfect sense, and that's exactly how my application is structured (instantiating the MainAppScreen class before enterEventDispatcher). So it sounds like...

- invokeAndWait -- this is more or less trying to put the pushModalScreen operation on the event thread which isn't even started yet, which is causing the runtime error

- invokeLater -- allows the program to wait until it can actually put something on the event thread, but that wouldn't be until after my MainAppScreen does all of its initialization.

Thanks a lot for that explanation. Why can't I simply call UiApplication.getUiApplication.pushModalScreen (or just pushScreen) in the MainAppScreen initialization (without queuing it up for the event thread). This MainAppScreen class has several other UI components that work fine before the event dispatcher thread is invoked.

because a Modal screen implies waiting. Nothing will get actioned, in terms of events like Key press, until you have 'entered the Dispatcher'. So even if your screen was displayed, there is no Thread in place to process key strokes that would respond to the screen.

"This MainAppScreen class has several other UI components that work fine"