1

こんにちは、バックグラウンド アプリケーションからグローバルに画面をプッシュすることを制御したいと思います。現在、MainScreen を拡張する Screen を作成しました。この画面をグローバルに表示したい。pushGlobalScreen(Screen to push, int priority, flag);次々に表示される2つの画面がある場合、私はその作業を使用 しています。しかし、私が実際にやりたいことはです。最初の画面を閉じてから、次の画面を表示したいなど。それで、これを達成する方法。

ここで私はそれをより明確に説明しています

現在の時刻がアラーム時刻と一致する場合にデータベースで時刻をチェックしているシナリオ全体を説明し、同時に複数のアラームが保存されていると仮定して画面をプッシュします。

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があるかどうかを確認して、1つの画面のみをプッシュすることです。そしてそれを閉じる前に、私はテーブルにもっとIDがあるかどうかをチェックしていますupdating the Contents of the Screen。これで、希望どおりに機能し、データがなくなった場合は画面を閉じます。

于 2012-07-19T09:14:15.653 に答える