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
Developer
Posts: 81
Registered: ‎06-24-2009
My Device: Not Specified
Accepted Solution

How to get class of active screen?

Hello all,

 

I have a worker thread that fetches data over HTTP. I then need to call on method on the screen to update various fields.

 

Is there a better way to determine the class of the active screen than something like this?

 

UiApplication.getUiApplication().invokeLater(new Runnable() {
   public void run() {

      Screen screen = UiApplication.getUiApplication().getActiveScreen();
      if(screen instanceof MyScreen) {
         ((MyMainScreen)screen).someMethod();
         screen.invalidate();

   }

});

 

Thanks

Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: How to get class of active screen?

This should not be a problem.

Use Search. "Accept Solution" If the problem is resolved.
Developer
Posts: 16,986
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to get class of active screen?

give your worker thread a callback or register all screens that need data as listeners and you don't have to find out the screen.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 81
Registered: ‎06-24-2009
My Device: Not Specified

Re: How to get class of active screen?

Interesting. You have links with more info about these two techniques?

 

Thanks.

Developer
Posts: 16,986
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to get class of active screen?

callback:
http://www.javaworld.com/javaworld/javatips/jw-javatip10.html
listener:
http://java.sun.com/docs/books/tutorial/uiswing/events/index.html (just use the general part).

if you have several screens you can do it like this:
create an interface
create a method dataAvailable(...) that has the needed data as an argument
implement the interface in all screens that need the data
give your thread a list (vector) of all screens implementing this interface
when your thread is finished you iterate through the list, cast the single element to your interface and call dataAvailable. Don't forget to use invokelater to sync on the event thread.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter