加载屏幕在Blackberry中不起作用?

时间:2011-10-14 08:44:29

标签: multithreading blackberry popup

我想在黑莓手机中实现加载屏幕。我使用以下代码

尝试跟随Support forum link的代码
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

问题是段2在完成段1之前有效。我还尝试以下代码

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 processing the data get from network call

出现同样的问题。任何帮助将不胜感激。

感谢

1 个答案:

答案 0 :(得分:1)

实际上它取决于你在段2中做了什么。如果没有UI动作,那么只需在进行http调用的线程内移动段2。 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();

但如果在段2中有UI动作,则在弹出等待屏幕后立即在UI线程上调用它:

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