redline
redline

Reputation: 224

Is there any event to catch when pop() a screen after back button pressed?

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?

Upvotes: 4

Views: 949

Answers (4)

Fostah
Fostah

Reputation: 11776

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.

Upvotes: 2

Michael Donohue
Michael Donohue

Reputation: 11876

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().

Upvotes: 1

Vit Khudenko
Vit Khudenko

Reputation: 28418

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);
}

Upvotes: 2

Amareswar
Amareswar

Reputation: 2064

I think this can be done using YUI History manager.

Upvotes: -1

Related Questions