开发者

Run code synchronously with a PopupScreen or Dialog on BlackBerry

I have a program that will get messages from a server and store them locally. If the message header, but not the message itself, exists locally, the program downloads the message while displaying a popup saying the download is taking place a开发者_如何学JAVAs well as a "cancel" button should the user want to abort the download.

In the BlackBerry API, there doesn't seem to be a way of running something gracefully with a popup or dialog -- gracefully meaning being able to run a method, and once the method finishes, the popup closes.

I've looked through the BlackBerry API, but couldn't find anything.


Your code to get the message body is relatively long lived, so it should not run with the UI event lock - if it did, the Cancel button wouldn't work and the BlackBerry OS would kill your application as it would stop responding to UI events while doing the download.

So you run the download code on a separate thread, by using Thread. You start the thread at the same time the dialog is presented to the user. To make the dialog close when the thread is finished, you will need to use Application.invokeLater(...) from the thread started at the beginning of the operation. The invokeLater() call can close the dialog and allow the application to continue. As for a 'cancel' button, you will need to set some cancel bit, and have the separate thread check occasionally and then exit.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜