When a button is pressed on Screen A, I push Screen B. And when Back button is pressed on Screen B, I want Screen A to understand that to update Screen. Is there any way to handle this?
4 Answers
When Screen B is popped, it will have its onUiEngineAttached(boolean) function called, with the parameter set to false. If Screen B held a reference to Screen A, it could then trigger whatever updating is needed.
Another way is to setup your own Listener where Screen B would provide the event and Screen A would listen for the event. Again, you would probably fire the event from the onUiEngineAttached(boolean) function.
-
Thank you, i will try onUiEngineAttached(boolean) method. – redline May 10 '11 at 13:37
You could use a callback pattern. Check my another post for details. Upon any UI event on your Screen B (e.g. a button is pressed) the Screen B runs the callback passing any parameter if needed. Going this way your Screen A keeps its original/clean interface.
You can detect the device 'Back' btn press with this code:
protected boolean keyChar(char c, int status, int time) {
if (c == Characters.ESCAPE) {
// .. run callback here ..
close(); // actually close the Screen B
return true;
}
return super.keyChar(c, status, time);
}

- 1
- 1

- 28,288
- 10
- 63
- 91
-
I already use `keyChar()`. And I just passed the reference of Screen A to Screen B and called an update method of A. It works but I don't know if it is a good way to pass the reference. I don't really know what callbacks do. But I use a ListField and ListCallBack in Screen A. I realize that `drawListRow()` method of ListCallback is called when I press back button from Screen B. So I think a callback will be usefull here. I will look into it, thank you. – redline May 10 '11 at 13:34
-
Just to be clear: I am not talking about ListCallBack. This is totally another concept. Passing a reference works Ok, it just creates a too monolithic code, that will be harder to change later. – Vit Khudenko May 10 '11 at 13:44
-
Yes, i know it won't be a ListCallBack ofcourse. And I am aware of problems of passing parameter, I will change it. – redline May 10 '11 at 13:57
Screen B is popped off of the stack, so it will get the onUiEngineAttached() callback. But you are interested in screen A, which will get a different callback - Screen.onExposed().

- 11,776
- 5
- 31
- 44