12-17-2010 09:31 AM
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,
12-17-2010 10:26 AM
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.
12-17-2010 10:39 AM
@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.