tags:

views:

29

answers:

1

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 as 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.

A: 

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.

Michael Donohue