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

Posts: 10
Registered: ‎12-17-2010
My Device: 8520
My Carrier: Vodaphone

Calling a method from within the screen



I'm a first time poster / long time reader of these forums, normally I find my questions answered long before I need to post but am having trouble finding anything on this topic and any help given is much appreciated.


I'm writting an app for school inspectors to use. Each time they visit a school a visit is created and each visit has many events, a typical event may be "broken sink" etc. Both event and visit need a screen for diplaying details, editing a current event/visit and adding a new one. All data is store on an external server using web service calls.


So when viewing details of an event you have the option to edit that event, this pushes the edit event screen ontop of the stack, the user makes the desired changes and finally hits update to send these changes to the server and pop the edit screen from the stack. The problem is the details screen is still displaying the unedited details! To solve this problem I wrote a public method in the details screen which accepts a visit object and fills all the fields on that screen accordingly.


My question is: Is it possible to invoke methods on a screen which isn't currently the active screen but is in the screen stack.  


Thanks for reading,


Posts: 67
Registered: ‎09-01-2009
My Device: Blackberry 9000 Bold
My Carrier: Rogers

Re: Calling a method from within the screen

I do this often.  My solution which may not be a good coding style, but it works, is as follows.


When pushing the edit screen, pass a reference of the display screen.  By doing this you now have access to the display screen's public methods and variables from the edit screen.  The user will update the data on the edit screen.  When they save then call a method on the display screen that will update the data on the display screen, then pop the edit screen.

Thanks, Brian
To error is human, but to really mess things up requires admin rights.

If this post has helped, don't be shy and click the kudo's star !!!
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Calling a method from within the screen

@BriGuy: In my view your solution is an absolutely fine coding style.


An alternative would be to either check getScreenBelow which is unreliable or to keep a list of "subscribed" screens which would "listen" to your edit screen. The latter is the famous "observer" pattern and is valid under other circumstances.  However, in your case the display screen is the one who initiates the whole process and so is entitled to get the result of that process.

please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!