07-24-2012 03:02 PM
I have an app with ui and background thread. I have the following code in background thread.
Screen scr = Ui.getUiEngine().getActiveScreen();
when I run the app, scr always returns null. What should I do differently to get active screen or the top screen.
07-24-2012 04:25 PM
gets access to the UiEngine for this process (see JavaDoc), so getActiveScreen() will return the active screen fro the currently running process. So, you can only use this method to get access to your own screens. You can not use it to get the currently displayed screen in general. In fact, there is no way to do that.
07-24-2012 04:56 PM
I'm not sure what your question is. But here are some thoughts.
Are you trying to get your active screen (i.e. the top most one in your application) or the top most screen (i.e. the one that is currently displayed?
Are you starting the background process as a different entry point? If you are, then it is a different process and will not have access to your Ui Applications screens.
Are you aware that calling invalidate() only causes a screen's paint method to be invoked? it does not by itslef, change the content of the Fields on the screen. Is that what you want?
Perhaps you can tell us what you are trying to achieve as we might be able to suggest a different approach.
07-24-2012 05:14 PM
Thank you Peter for your response. Here is what I try to accomplish in the app. There are several screens in UI that includes a ListField screen and other ui screens, and a background listener that listens a push message. when a message arrives, the message will be added the ListField screen. I had hard time update the ListField screen.
07-24-2012 05:32 PM
Here is a quick and dirty way to get this going. Once you have this going, think about how it could be done in a clear fashion.
Create a method in your ListField Screen that the background thread can call, passing in the new data. Now the trick is, how does the Background Thread find the screen? The simplest approach is to put the screen in a known place - and RuntimeStore provides such a place, as describe din this KB article
Once you have go this going, think about how you would do this 'nicely'. I'm pretty hopeless at this sort of thing, you will get better ideas and more correct ideas from other people. But one approach you might consider is to have a Registration Object, have the ListField register an interest in new data of a specific sort, and have the Background Thread supply the data to the Registration Object.