문제

I have a blackberry application in which i want to show a "please wait" modal screen(which is a FullScreen push as modal screen) while sending a server request and if the user hitting the device back button , pop the modal screen and current active screen.This works fine.

My problem is that : I used a callback for server request in the active screen.But the callback executed even after popped up the screen.

Exactly whats happening while calling popScreen()? How can i remove all callbacks and refresh the screen if the user pressing back button while server request happens?

Thanks in Advance

도움이 되었습니까?

해결책

There are several solutions to this problem of course. I guess the server request is sent asynchronously.

  • The simplest way I think out is having a flag and when the callback is triggered check whether the user cancelled the action (pressing the back button).

  • Another solution, perhaps not that nice is to check whether the Loading Screen is still in the display stack.

  • What I think would be a proper solution is to have a stack of cancelled http operations, so you can stop requests at any time. Then if the request to the server has been sent, before calling the callbacks you can check if the operation has been cancelled. Otherwise, you just avoid sending the request to the server.

When you call popScreen, the screen which is on top of the display stack (the screen in the foreground) is removed from the stack and the Screen is refreshed (a paint event is triggered) to reflect the changes. Make sure you execute Screen.pop() on the UiThread:

UiApplication.getUiApplication().invokeLater(runnable)

In your scenario, how is the callback handled? Is it a delegate you passed along with the request or is a listener you register?

When I refer to delegate I mean something like the following:

Server.sendRequest(request, objectWithCallbacks)

and callbacks of the objectWithCallbacks (and only objectWithCallbacks) will be called accordingly. On the other hand, a listener would be something like:

Server.addListener(objectWithCallbacks, request)
Server.sendRequest(request);

this way, all the objects listening to "eventName" will get their callbacks triggered accordingly.

As far as I see, your callback will be always executed but in the callback itself you can check if the screen is currently displayed.

if( this.isDisplayed() ) {
    // Do the magic
}else{
    // Do nothing
}

Good Luck

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top