1

大家好,我想控制从后台应用程序全局推送屏幕。目前我制作了一个扩展 MainScreen 的屏幕。我想在全球范围内显示这个屏幕。如果有两个屏幕一个接一个地显示,我正在使用 pushGlobalScreen(Screen to push, int priority, flag);它。但实际上我想做的是。我想关闭第一个屏幕然后我想显示下一个屏幕等等。那么如何实现这一点。

这里我解释得更清楚

我正在解释我在数据库中检查时间的整个场景,如果当前时间与警报时间匹配,那么它会推动屏幕,假设同时保存了多个警报。

while (Checking into database for time){
if (databasetime == current time ) {// let suppose there is more than 
                                    //one alarm save for the same time
    synchronized (getEventLock()) {// This will call one after other but i want to first

        UiEngine ui = Ui.getUiEngine();

        ui.pushGlobalScreen(new AlarmScreen() , 1, UiEngine.GLOBAL_QUEUE);//  
                      //Here i want to stop. I want user to close the screen then
                      // i want to push again the screen. As we do in
                      // PushModalScreen(Screen) How can i block 
                     //pushGlobalScreen(new AlarmScreen() , 1, UiEngine.GLOBAL_QUEUE);
         }

   }

}

我想我的要求现在很清楚了。是吗??

4

2 回答 2

2

AlarmScreen在推送新实例之前,请检查以下代码片段以从显示堆栈中删除AlarmScreen实例。

net.rim.device.api.ui.Screen currentScreen = Ui.getUiEngine().getActiveScreen();

// pop previously pushed AlarmScreen
if (currentScreen instanceof AlarmScreen) {
    try {
        Ui.getUiEngine().popScreen(currentScreen);
    } catch (IllegalArgumentException iaexc) {
        // If your screen is not on the stack.
    } catch (Exception exc) {           
    }
}

// push new AlarmScreen
synchronized (Application.getEventLock()) {
    Ui.getUiEngine().pushGlobalScreen(new AlarmScreen() , 1, UiEngine.GLOBAL_QUEUE);
}




以下应用程序(UiApplication)使用队列AlarmScreen。在从显示堆栈中主动AlarmScreen移除时,它将另一个AlarmScreen从等待队列推入显示堆栈。

package mypackage;

import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;

public class MyApp extends UiApplication implements CloseEventListener {
    public static void main(String[] args) {
        (new MyApp()).enterEventDispatcher();
    }

    private AlarmScreen []queue;
    private int MAX = 10;
    private int head = 0;

    public MyApp() {
        // initialize queue 
        queue = new AlarmScreen[MAX];
        head = 0;
        for (int i=0;i<MAX;i++) {
            queue[i] = new AlarmScreen(this, "Screen no. " + i);
        }

        // push first screen on display
        UiApplication.getUiApplication().pushScreen(queue[head ++]);
    }

    public void screenClosed() {
        if (head < MAX) {
            UiApplication.getUiApplication().pushScreen(queue[head ++]);
        }
    }
}

interface CloseEventListener {
    public void screenClosed();
}

class AlarmScreen extends MainScreen {
    private CloseEventListener listener;

    public AlarmScreen(CloseEventListener listener, String title) {
        setTitle(title);
        this.listener = listener;
    }

    public boolean onClose() {
        try {
            UiApplication.getUiApplication().invokeLater(new Runnable() {
                public void run() {
                    close();
                }
            });
        } catch (Exception exc) {
            System.out.println(exc.getMessage());
        }
        // push a new screen from waiting queue
        if (listener != null) {
            listener.screenClosed();
        }
        return true;
    }
}
于 2012-04-26T11:18:08.503 回答
0

我已经解决了这个问题,但方式不同。我选择的方式是,我将所有 id 存储在表中并检查表中是否有任何 id 我只推送一个屏幕。在关闭它之前,我正在检查表中是否有更多的 id updating the Contents of the Screen。现在它按我想要的方式工作,如果没有更多数据,我只是关闭屏幕。

于 2012-07-19T09:14:15.653 回答