gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 04:48:41 25 4
gpt4 key购买 nike

大家好,我想控制从后台应用程序全局推送屏幕。目前我制作了一个扩展主屏幕的屏幕。我想在全局范围内显示此屏幕。我在用pushGlobalScreen(Screen to Push, intpriority, 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);
}

}

}

我想我的要求现在已经很明确了。是吗??

最佳答案

在推送新的 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 队列。从显示堆栈中删除 Activity 的 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;
}
}

关于java - 从后台进程全局控制推送屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10330591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com