从后台进程全局控制推送屏幕

时间:2012-04-26 09:22:30

标签: java blackberry

大家好,我想控制从后台应用程序全局推送屏幕。目前我做了一个屏幕扩展了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);
         }

   }

}

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

2 个答案:

答案 0 :(得分: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;
    }
}

答案 1 :(得分:0)

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