Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 13
Registered: ‎10-06-2011
My Device: Torch 9780
My Carrier: TMobile

getActiveScreen() returns null

I have an app with ui and background thread. I have the following code in background thread.

 synchronized(Application.getEventLock())
 {     

 Screen scr = Ui.getUiEngine().getActiveScreen();

scr.invalidate();

}

when I run the app, scr always returns null. What should I do differently to get active screen or the top screen.

Thank you!

Developer
Posts: 19,631
Registered: ‎07-14-2008
My Device: Not Specified

Re: getActiveScreen() returns null

Note that

Ui.getUiEngine().

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. 

Contributor
Posts: 13
Registered: ‎10-06-2011
My Device: Torch 9780
My Carrier: TMobile

Re: getActiveScreen() returns null

Thank you Peter for your response. The code is from the same process but from the different thread, the background thread to update ui screen.

Developer
Posts: 19,631
Registered: ‎07-14-2008
My Device: Not Specified

Re: getActiveScreen() returns null

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. 

Contributor
Posts: 13
Registered: ‎10-06-2011
My Device: Torch 9780
My Carrier: TMobile

Re: getActiveScreen() returns null

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.

Developer
Posts: 19,631
Registered: ‎07-14-2008
My Device: Not Specified

Re: getActiveScreen() returns null

OK, understood.

 

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

http://supportforums.blackberry.com/t5/Java-Development/Create-a-singleton-using-the-RuntimeStore/ta...

 

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. 

Contributor
Posts: 13
Registered: ‎10-06-2011
My Device: Torch 9780
My Carrier: TMobile

Re: getActiveScreen() returns null

Thank you Peter. I will try some of your suggestions.