I want to implement a loading screen in blackberry. I try the code from following Support forum link using following code
PleaseWaitPopupScreen.showScreenAndWait(new Runnable() {
public void run() {
//**Segment 1** here i write the code for network call
}
}, "please wait");
// **Segment 2**:Here processing the data get from network call
the problem is the segment 2 works before completing the segment 1. I also try the following code
HorizontalFieldManager popHF = new HorizontalFieldManager();
popHF.add(new LabelField("Pls wait..."));
final PopupScreen waitScreen = new PopupScreen(popHF);
new Thread()
{
public void run()
{
synchronized (UiApplication.getEventLock())
{
UiApplication.getUiApplication().pushScreen(waitScreen);
}
// **Segment 1**Here Some Network Call
synchronized (UiApplication.getEventLock())
{
UiApplication.getUiApplication().popScreen(waitScreen);
}
}
}.start();
// **Segment 2**:Here pr开发者_开发技巧ocessing the data get from network call
the same problem arises. Any help will be appreciated.
thanks
Actually it depends on what you're doing in segment 2. If there is no UI actions, then just move segment 2 inside the thread that makes http call. e.g.:
final PopupScreen waitScreen = new PopupScreen(popHF);
new Thread()
{
public void run()
{
synchronized (UiApplication.getEventLock())
{
UiApplication.getUiApplication().pushScreen(waitScreen);
}
// **Segment 1**Here Some Network Call
// **Segment 2**:Here processing the data get from network call
synchronized (UiApplication.getEventLock())
{
UiApplication.getUiApplication().popScreen(waitScreen);
}
}
}.start();
But if there are UI actions inside of segment 2, then call it on UI thread, right after you pop off the wait screen:
final PopupScreen waitScreen = new PopupScreen(popHF);
new Thread()
{
public void run()
{
synchronized (UiApplication.getEventLock())
{
UiApplication.getUiApplication().pushScreen(waitScreen);
}
// **Segment 1**Here Some Network Call
synchronized (UiApplication.getEventLock())
{
UiApplication.getUiApplication().popScreen(waitScreen);
// **Segment 2**:Here processing the data get from network call
}
}
}.start();
精彩评论