工作线程无法更新 Motorola V3 上的 UI

发布于 2024-10-13 19:10:33 字数 635 浏览 4 评论 0原文

我正在开发一个 J2ME 应用程序,该应用程序应该移植到不同供应商的手机上。到目前为止,该应用程序运行良好,除了 Motorola V3(这是我尝试过的唯一一款摩托罗拉手机)。

问题是,当我启动一个新线程,并且当该线程尝试更新图形(通过调用 repaint())时,图形系统是堆栈。

一些有用的信息: - 我在 Midlet 的构造函数中获取显示内容,并在应用程序生命周期内重用它。 - 只有一个类扩展 Canvas。每幅画都发生在这里。当我想要重新绘制图形时,我从 UI 线程或另一个工作线程调用 repaint() 方法。据我所知,每个线程都可以毫无问题地访问UI。 - 我尝试了一个修复,在应用程序的开头,我获取正在运行的(UI)线程的名称并将其存储以供以后使用。在调用 repaint() 之前,我检查当前线程的名称是否等于 UI 线程的名称。如果是的话,那么我会执行repaint(),否则我会执行:

display.callSerially(new Runnable() {
    public void run() {
        repaint();
    }
});

您能给我指出 Motorola 实现 J2ME 的任何细节吗?如何通过线程更新 UI 来解决这个问题?

谢谢, 兹拉特科

I'm working on a J2ME application that should be ported to different vendors phones. So far, the application is working fine, except on the Motorola V3 (this is the only Motorola phone I have tried).

The problem is that when I start a new Thread, and when the thread tries to update the graphics (by calling repaint()), the graphic system is stack.

Some useful info:
- I'm obtaining the display in the constructor of the Midlet, and reusing it during the application lifespan.
- There is only one class extending Canvas. Every drawing happens here. When I want the graphics repainted, I call the repaint() method, either from the UI thread or from another Worker thread. As far as I know, every thread can access the UI without problems.
- I tried a fix where, in the beginning of the app, I take the name of the running (UI) thread and store it for later use. Before repaint() is called, I check if the current thread's name equals to the UI thread's name. If it odes, then I do repaint(), else I do:

display.callSerially(new Runnable() {
    public void run() {
        repaint();
    }
});

Can you point to me any specifics in the Motorola's implemenation of J2ME? How can I solve this problem with threads updating the UI?

Thanks,
Zlatko

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

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

发布评论

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

评论(1

水波映月 2024-10-20 19:10:33

与 Swing 不同,MIDP 用户界面 API 是线程安全的。这意味着您不必使用 callSerially 来强制在 UI 线程上运行。有报告称 callSerially 在某些摩托罗拉设备上无法正常工作,因此最好的选择是直接调用 repaint 本身。

请注意,重绘只是对系统进行重绘的建议。如果您想强制立即进行重绘,则必须调用 serviceRepaints 方法。

有关 MIDP UI 事件处理的详细讨论,请参见 此处

Unlike Swing, the MIDP user interface APIs are thread-safe. This means you don't have to use callSerially to force things to run on the UI thread. There are reports that callSerially doesn't work well on some Motorola devices, so your best bet is to just call repaint by itself.

Note that repaint is just a suggestion to the system to do the repainting. If you want to force the repaints to occur immediately, you have to call the serviceRepaints method.

A good discussion of MIDP UI event handling can be found here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文