Static News Archive

   (27-Dec-07 9:17)  3 Helpful blackberry development tips
If you are like me and have just started on blackberry development, there are quite a few traps for young players.

Here are 3 nice and simple tips to help you get around some of the hurdles of BB Dev.

1) Updating UI from a thread.
If you try to set the text of a label, add something to a textfield, or some other GUI action from anything BUT the main application thread,
you will get an exception:
"UI engine accessed without holding the event lock".

This is so the blackberry can ensure there is only one thread accessing its gui controls, and prevents thread locking and other nasty threading issues.
To get around this, a lot of people seem to suggest using the UiApplication.getApplication().invokeLater() or UiApplication.getApplication().invokeAndWait() methods.
In my experience, these work in that they don't throw the exception, but the UI takes it's sweet time to update.
In fact, I didnt see the updates, because I switch screens before the request can be processes by the event queue.

A better solution is to tell the event queue to stop processing events, process your event, then return control.
This is done by getting a hold on the event locking object:

    public final void safeSetLabelText(LabelField f, String text) {
synchronized (UiApplication.getApplication().getEventLock()) {

2) Running a blocking operation on a button click.
This problem is somewhat related to the above issue.
If you want to do something like download a file when you click a button, you will likely be using a blocking http read operation.
If you do, then the application will throw a runtime exception: "blocking operation not permitted on event dispatch thread"

This is because the event thread is looping along, processing events nicely, until your button click comes along and stops everything until the operation is complete.
This is not good from a UI point of view, because any user input cannot be processed until the blocking operation is complete.

To get around this, simply spawn a new thread for your blocking operation to run in. This will have the thread running synchronously with the event thread.

        Thread t = new Thread(new Runnable() {
public void run() {
//TODO - add blocking operation in here
t.start(); //dont forget to call start!

3) Removing those annoying confirm changes/save prompt messages
The blackberry comes with a nice feature that handles "dirty" screens, and allows developers to handle the save process themselves without having to do the whole 'check if any fields have been changed' logic.
However, in screens which don't require this logic, you still get the save prompt message coming up.
To get around this, simple override the onClose method in the MainScreen class

    public boolean onClose() {
//by default, this method would usually call onSavePrompt() if a call to isDirty() returns true.
close(); //just close this form, without any of that save prompt stuff
return true; //we were successful :)

So there you have it - 3 nice simple tips to get around some tough issues for beginner Blackberry developers.


Post a comment     
(13-Dec-08 12:29)  Posted by Chris
Thanks Rob,

Very clean explanation and good ideas. When I first discovered the Exception
I thought I was done with RIM (OMG OMG!!! head banging against the wall etc.).
There are few things revealed about the inner works of the UI engine and a speculative
approach in matter would have failed me anyway. Other people posting about the problem
solved the issue with the tricks you've mentioned as being suggested but gave no reason
why or how exactly their fix worked.

Thanks and keep them coming.

(23-Dec-08 10:36)  Posted by Nankerphelgue
Mmm im a very newbie developing for blackberry
can you help me this is my idea :
Main Class
public static void main(String[] args)
Main main = new Main();

private void execute(){
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
pushScreen(new InboxScreen());
Inbox Screen Class
public InboxScreen(){
Thread threadGetInboxData = new Thread(){
public void run(){
InboxController.getResults(1, "XXXXXX");
public static void updateResultInboxContainer(TableListField tlf){
synchronized (UiApplication.getApplication().getEventLock()) {
// vfm is a manager o container for the tlf
public static void getResults(int _pageNumber, String _pin){
ConnectionRecieve serverConnection = new ConnectionRecieve(URL, HOST, queryString, data, false);
Thread thread = new Thread(serverConnection);
inputStreamResponse = serverConnection.getResponse();
if(serverConnection.getErrorConnection() || inputStreamResponse!=null) {
(19-Aug-11 9:22)  Posted by Very good content creates regular advancement, thanks a lot talk
Very good content creates regular advancement, thanks a lot talk about, your piling up involving know-how should be to preserve mastering, awareness can be the start of riches.
<a href="">chi flat iron</a>
<a href="">cheap chi flat iron</a>
<a href="">chi hair straightener</a>
<a href="">chi hair products</a>
<a href="">wholesale chi flat iron</a>
<a href="">wholesale chi hair straighteners</a>
<a href="">CHI Pink Dazzle Flat Iron</a>
<a href="">chi original ceramic flat iron</a>
<a href="">CHI Camo Collection Blue</a>
<a href="">chi flat iron coupon</a>
<a href="">ghd straighteners</a>
<a href="">ghd hair straighteners</a>
<a href="">cheap ghd straighteners</a>
<a href="">ghd uk</a>
<a href="">ghd straighteners</a>
<a href="">ghd Hair Straighteners</a>
<a href="">Cheap ghd</a>
<a href="">ghd Sale</a>
<a href="">ghd iv styler</a>
<a href="">pink ghd</a>
<a href="">Classic ghd</a>
<a href="">ghd Purple</a>
<a href="">Vibram Five Fingers Shoes</a>
<a href="">cheap vibram five fingers</a>
<a href="">vibram five fingers kso</a>
<a href="">vibram five fingers classic</a>
<a href="">vibram five fingers bikila</a>
<a href="">vibram five fingers sale</a>
<a href="">cheap oakley sunglasses</a>
<a href="">oakley sunglasses cheap</a>
<a href="">discount oakley sunglasses</a>
<a href="">Oakley Photochromic Sunglasses</a>
<a href="">Oakley Limited Editions Sunglasses</a>
<a href="">Oakley Asian Fit Sunglasses</a>
<a href="">Oakley Lifestyle Sunglasses</a>
<a href="">Oakley Active Sunglasses</a>
<a href="">Oakley Sport Sunglasses</a>
<a href="">oakley women sunglasses</a>
<a href="">oakley men sunglasses</a>
<a href="">wholesale oakley sunglasses</a>
Hot sunmmer coming, why not choose a pair <A href="">vibram five fingers shoes</A> with <A href="">cheap Oakley Sunglasses</A> with <A href="">cheap vibram five fingers shoes</A> do water play. <A href="">vibram five fingers kso</A>
(19-Aug-11 9:23)  Posted by chi flat iron
Beneficial document helps make frequent advance, appreciate it write about, this pile-up connected with expertise is usually to hold finding out, focus is usually the beginning of money.
[url=]chi flat iron[/url]
[url=]cheap chi flat iron[/url]
[url=]chi hair straightener[/url]
[url=]wholesale chi flat iron[/url]
[url=]wholesale chi hair straighteners[/url]
[url=]CHI Pink Dazzle Flat Iron[/url]
[url=]chi original ceramic flat iron[/url]
[url=]CHI Camo Collection Blue[/url]
[url=]chi flat iron coupon[/url]
[url=]wholesale chi hair straighteners[/url]
[url=]ghd straighteners[/url]
[url=]cheap ghd straighteners[/url]
[url=]cheap ghd straighteners[/url]
[url=]ghd uk[/url]
[url=]ghd straighteners[/url]
[url=]ghd Hair Straighteners[/url]
[url=]Cheap ghd[/url]
[url=]ghd iv styler[/url]
[url=]pink ghd[/url]
[url=]Classic ghd[/url]
[url=]ghd Purple[/url]
[url=]Vibram Five Fingers Shoes[/url]
[url=]cheap vibram five fingers[/url]
[url=]vibram five fingers cheap[/url]
[url=]vibram five fingers kso[/url]
[url=]vibram five fingers classic[/url]
[url=]vibram five fingers bikila[/url]
[url=]vibram five fingers sale[/url]
[url=]cheap oakley sunglasses[/url]
[url=]discount oakley sunglasses[/url]
[url=]Oakley Photochromic Sunglasses[/url]
[url=]Oakley Limited Editions Sunglasses[/url]
[url=]oakley women sunglasses[/url]
[url=]oakley men sunglasses[/url]
[url=]wholesale oakley sunglasses[/url]
[url=]Oakley Sport Sunglasses[/url]
[url=]oakley sunglasses cheap[/url]
Hot sunmmer coming, why not choose a pair [url=]vibram five fingers shoes[/url] with [url=]cheap Oakley Sunglasses[/url] with [url=]cheap vibram five fingers shoes[/url] do water play. [url=]vibram five fingers kso[/url]
(19-Aug-11 9:25)  Posted by Very good content creates regular advancement, thanks a lot talk
conditions of style and design equally for adult men and women,vibram five fingers sale,The footwear are stated to get created are 7000 BC to spend less the ft from any dirt or harm and to Vibram Five Fingers Shoes them comfortable. It has only evolved given that then. throughout the last century it has grown five fingers shoes in conditions of style and cheap vibram five fingers design equally for adult men and women. equally vibram five fingers bikila genders possess a different relationship with shoes. vibram five fingers kso Women are believed to get in love with them whereas adult men are believed to make use of them as just any other accessory. vibram five fingers classic But in today’s age of metro sexual adult men this isn’t a fact anymore.
(26-Feb-12 5:41)  Posted by happycoder
very great article! it helped me solved my programming problem, thanks a lot!
(11-Jul-12 4:45)  Posted by zhhyking
(10-Aug-12 10:37)  Posted by cheap gucci belts
[url=]Cheap Gucci Clothing[/url]
[url=]Cheap Louis Vuitton Shoes[/url]
[url=]Cheap YSL T Shirts[/url]
[url=]Cheap Gucci Shoes[/url]
[url=]Cheap Louis Vuitton Clothing[/url]
[url=]Cheap Prada Shoes[/url]
[url=]Cheap YSL T Shirts Men[/url]
[url=]Cheap Armani Watches[/url]
[url=]Cheap Louis Vuitton Belts[/url]
(29-Aug-12 4:32)  Posted by caoch outlet online coach outlet online coach outlet online coach outlet coach outlet

<-  (5-Dec-07 10:25)  Installing Visual St... (22-Jan-08 8:54)  Converting from delp...  ->