黑莓:提前显示警报/状态/对话框并退出

发布于 2024-11-28 12:27:53 字数 866 浏览 6 评论 0原文

假设我有一个典型的 Blackberry 应用程序:

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

    public MyApp() {
        pushScreen(new MyScreen());
    }    
}

一开始我就注意到缺少强制条件(显示尺寸错误;缺少 SD 卡;某些 IT 策略等)。

有没有办法显示简短的快速消息给用户(以警报/状态/对话框/任何形式)并立即退出 - 没有/在实例化复杂的屏幕/注册加速侦听器/安装复杂的 CleanupRunnable 之前?

我已经尝试过 状态.show()、Dialog.alert() - 它们不起作用(RuntimeException“非事件线程调用的pushModalScreen”):

public class MyScreen extends MainScreen {
    public MyScreen() {
        if (Display.getWidth() < 400) {
            Status.show("Goodbye");
            return;
        }
    }
}

Let's say I have a typical Blackberry app:

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

    public MyApp() {
        pushScreen(new MyScreen());
    }    
}

and already at the beginning I notice, that a mandatory condition is missing (wrong Display dimensions; missing SD card; some IT policy; etc.)

Is there a way to display a short and quick message to the user (in the form of Alert/Status/Dialog/whatever) and exit straight away - without/before instantiating a complex Screen/registering Acceleration listeners/installing complex CleanupRunnable?

I've tried Status.show(), Dialog.alert() - they do not work (RuntimeException "pushModalScreen called by a non-event thread"):

public class MyScreen extends MainScreen {
    public MyScreen() {
        if (Display.getWidth() < 400) {
            Status.show("Goodbye");
            return;
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

回梦 2024-12-05 12:27:53

使用invokeLater 代替直接调用。示例如下:

Application.getApplication().invokeLater(new Runnable() {
    public void run() {
        Dialog.inform("Your message here...");
    }
});

您可以使用 Status.show() 代替 Dialog.inform

Instead of direct invocation use invokeLater. Sample is below:

Application.getApplication().invokeLater(new Runnable() {
    public void run() {
        Dialog.inform("Your message here...");
    }
});

Instead of Dialog.inform you may use Status.show()

爱格式化 2024-12-05 12:27:53

实际上,以下内容比拉斐尔建议的更好 - 因为它下面没有丑陋的白色屏幕。这是我的完整示例 MyApp.java:

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.decor.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.image.*;

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

    public MyApp() {
        pushScreen(new MyScreen());
    }    
}

class MyScreen extends MainScreen implements DialogClosedListener {
    Dialog myDialog = new Dialog(Dialog.OK, "Goodbye!", 0, Bitmap.getPredefinedBitmap(Bitmap.EXCLAMATION), Dialog.GLOBAL_STATUS);

    public MyScreen() {
        // XXX just some condition, like wrong dimensions or IT policy
        if (Display.getWidth() > 40) {
            myDialog.setDialogClosedListener(this);
            Application.getApplication().requestBackground();
            Application.getApplication().invokeLater(new Runnable() {
                public void run() {
                    myDialog.show();
                }
            });
            return;
        }

        // XXX heavy stuff to be skipped
    }

    public void dialogClosed(Dialog dialog, int choice) {
        if (dialog == myDialog) {
            System.out.println("XXX exiting XXX");
            System.exit(1);
        }
    }
}

Actually the following is better, than what's suggested by Rafael - because it doesn't have the ugly white screen underneath. Here is my complete example MyApp.java:

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.decor.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.image.*;

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

    public MyApp() {
        pushScreen(new MyScreen());
    }    
}

class MyScreen extends MainScreen implements DialogClosedListener {
    Dialog myDialog = new Dialog(Dialog.OK, "Goodbye!", 0, Bitmap.getPredefinedBitmap(Bitmap.EXCLAMATION), Dialog.GLOBAL_STATUS);

    public MyScreen() {
        // XXX just some condition, like wrong dimensions or IT policy
        if (Display.getWidth() > 40) {
            myDialog.setDialogClosedListener(this);
            Application.getApplication().requestBackground();
            Application.getApplication().invokeLater(new Runnable() {
                public void run() {
                    myDialog.show();
                }
            });
            return;
        }

        // XXX heavy stuff to be skipped
    }

    public void dialogClosed(Dialog dialog, int choice) {
        if (dialog == myDialog) {
            System.out.println("XXX exiting XXX");
            System.exit(1);
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文