开发者

J2ME lcdui: Can I manipulate my GUI in a worker thread?

I'm just starting with J2ME and lcdui, and I'm looking at some sample code that calls methods on lcdui objects from a worker thread.

In my experience with desktop GUI toolkits, this is usually forbidden - is lcdui different? Is it really OK to do this?

(I've Goog开发者_JS百科led for an answer to this question but not found anything - a link to a defintive answer in some official documentation would be excellent!)


LCDUI is a bit of a funny one, what you can and can't do often depends on the implementation. I've written apps for BlackBerry that don't have a problem with accessing UI objects from a background thread (except the usual threading problems that you create yourself), but I'm pretty sure some other platforms will forbid this.

If you're concerned about this, or it's causing you issues, you might want to look at using javax.microedition.lcdui.Display.callSerially(Runnable). This executes the given Runnable object in the UI thread (if there is such a thing in LCDUI) and serializes it with other UI events and paint operations. You can read more about it in the J2ME API docs.


Using the javax.microedition.lcdui classes, thread-safety is supposedly one of the goals of the UI classes according to the Concurrency section of this documentation. As Rory indicated, it is entirely possible that different vendors implemented this as more of a "suggestion" rather than a rule.

At one time, I was looking for similar information, but was also unable to find the magic phrasing to offer Google to get good results.

Best of luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜