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()) {
f.setText(text);
}
}



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.

-Rob-

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.

Chris
(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();
main.execute();
main.enterEventDispatcher();
}

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
vfm.add(tlf);
}
}
-------------------------------------------
InboxController
public static void getResults(int _pageNumber, String _pin){
...
...
...
ConnectionRecieve serverConnection = new ConnectionRecieve(URL, HOST, queryString, data, false);
Thread thread = new Thread(serverConnection);
thread.start();
while(true){
inputStreamResponse = serverConnection.getResponse();
if(serverConnection.getErrorConnection() || inputStreamResponse!=null) {
break;
}
}
...
...
...
screenReference.updateResultInboxContainer(tableresults);
}
(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="http://www.2011chiflatiron.com">chi flat iron</a>
<a href="http://www.2011chiflatiron.com">cheap chi flat iron</a>
<a href="http://www.2011chiflatiron.com">chi hair straightener</a>
<a href="http://www.2011chiflatiron.com">chi hair products</a>
<a href="http://www.2011chiflatiron.com">wholesale chi flat iron</a>
<a href="http://www.2011chiflatiron.com">wholesale chi hair straighteners</a>
<a href="http://www.2011chiflatiron.com/chi-pink-dazzle-flat-iron-1.html">CHI Pink Dazzle Flat Iron</a>
<a href="http://www.2011chiflatiron.com/chi-original-ceramic-flat-iron.html">chi original ceramic flat iron</a>
<a href="http://www.2011chiflatiron.com/chi-camo-collection-blue.html">CHI Camo Collection Blue</a>
<a href="http://www.2011chiflatiron.com/chi-flat-iron.html">chi flat iron coupon</a>
<a href="http://www.cheapghdstraightenerssales.co.uk">ghd straighteners</a>
<a href="http://www.cheapghdstraightenerssales.co.uk">ghd hair straighteners</a>
<a href="http://www.cheapghdstraightenerssales.co.uk">cheap ghd straighteners</a>
<a href="http://www.cheapghdstraightenerssales.co.uk">ghd uk</a>
<a href="http://www.ghdstraightenersshop.co.uk/">ghd straighteners</a>
<a href="http://www.ghdstraightenersshop.co.uk/">ghd Hair Straighteners</a>
<a href="http://www.ghdstraightenersshop.co.uk/">Cheap ghd</a>
<a href="http://www.ghdstraightenersshop.co.uk/">ghd Sale</a>
<a href="http://www.ghdstraightenersshop.co.uk/ghd-iv-styler.html">ghd iv styler</a>
<a href="http://www.ghdstraightenersshop.co.uk/2010-pink-ghd.html">pink ghd</a>
<a href="http://www.ghdstraightenersshop.co.uk/classic-rare-ghd.html">Classic ghd</a>
<a href="http://www.ghdstraightenersshop.co.uk/new-ghd-purple.html">ghd Purple</a>
<a href="http://www.vibramfivefingerscheaps.com">Vibram Five Fingers Shoes</a>
<a href="http://www.vibramfivefingerscheaps.com">cheap vibram five fingers</a>
<a href="http://www.vibramfivefingerscheaps.com/vibram-five-fingers-kso.html">vibram five fingers kso</a>
<a href="http://www.vibramfivefingerscheaps.com/vibram-five-fingers-classic.html">vibram five fingers classic</a>
<a href="http://www.vibramfivefingerscheaps.com/vibram-five-fingers-bikila.html">vibram five fingers bikila</a>
<a href="http://www.vibramfivefingerscheaps.com">vibram five fingers sale</a>
<a href="http://www.discountoakleysunglassescheap.com">cheap oakley sunglasses</a>
<a href="http://www.discountoakleysunglassescheap.com">oakley sunglasses cheap</a>
<a href="http://www.discountoakleysunglassescheap.com">discount oakley sunglasses</a>
<a href="http://www.discountoakleysunglassescheap.com">Oakley Photochromic Sunglasses</a>
<a href="http://www.discountoakleysunglassescheap.com">Oakley Limited Editions Sunglasses</a>
<a href="http://www.discountoakleysunglassescheap.com">Oakley Asian Fit Sunglasses</a>
<a href="http://www.discountoakleysunglassescheap.com/oakley-lifestyle-sunglasses.html">Oakley Lifestyle Sunglasses</a>
<a href="http://www.discountoakleysunglassescheap.com/oakley-active-sunglasses.html">Oakley Active Sunglasses</a>
<a href="http://www.discountoakleysunglassescheap.com/oakley-sport-sunglasses.html">Oakley Sport Sunglasses</a>
<a href="http://www.discountoakleysunglassescheap.com">oakley women sunglasses</a>
<a href="http://www.discountoakleysunglassescheap.com">oakley men sunglasses</a>
<a href="http://www.discountoakleysunglassescheap.com">wholesale oakley sunglasses</a>
Hot sunmmer coming, why not choose a pair <A href="http://www.vibramfivefingerscheaps.com/">vibram five fingers shoes</A> with <A href="http://www.discountoakleysunglassescheap.com/">cheap Oakley Sunglasses</A> with <A href="http://www.vibramfivefingerscheaps.com/">cheap vibram five fingers shoes</A> do water play. <A href="http://www.vibramfivefingerscheaps.com/vibram-five-fingers-kso.html/">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=http://www.2011chiflatiron.com]chi flat iron[/url]
[url=http://www.2011chiflatiron.com]cheap chi flat iron[/url]
[url=http://www.2011chiflatiron.com]chi hair straightener[/url]
[url=http://www.2011chiflatiron.com]wholesale chi flat iron[/url]
[url=http://www.2011chiflatiron.com]wholesale chi hair straighteners[/url]
[url=http://www.2011chiflatiron.com/chi-pink-dazzle-flat-iron-1.html]CHI Pink Dazzle Flat Iron[/url]
[url=http://www.2011chiflatiron.com/chi-original-ceramic-flat-iron.html]chi original ceramic flat iron[/url]
[url=http://www.2011chiflatiron.com/chi-camo-collection-blue.html]CHI Camo Collection Blue[/url]
[url=http://www.2011chiflatiron.com]chi flat iron coupon[/url]
[url=http://www.2011chiflatiron.com/chi-flat-iron.html]wholesale chi hair straighteners[/url]
[url=http://www.cheapghdstraightenerssales.co.uk]ghd straighteners[/url]
[url=http://www.cheapghdstraightenerssales.co.uk]cheap ghd straighteners[/url]
[url=http://www.cheapghdstraightenerssales.co.uk]cheap ghd straighteners[/url]
[url=http://www.cheapghdstraightenerssales.co.uk]ghd uk[/url]
[url=http://www.ghdstraightenersshop.co.uk/]ghd straighteners[/url]
[url=http://www.ghdstraightenersshop.co.uk/]ghd Hair Straighteners[/url]
[url=http://www.ghdstraightenersshop.co.uk/]Cheap ghd[/url]
[url=http://www.ghdstraightenersshop.co.uk/ghd-iv-styler.html/]ghd iv styler[/url]
[url=http://www.ghdstraightenersshop.co.uk/2010-pink-ghd.html]pink ghd[/url]
[url=http://www.ghdstraightenersshop.co.uk/classic-rare-ghd.html]Classic ghd[/url]
[url=http://www.ghdstraightenersshop.co.uk/new-ghd-purple.html]ghd Purple[/url]
[url=http://www.vibramfivefingerscheaps.com]Vibram Five Fingers Shoes[/url]
[url=http://www.vibramfivefingerscheaps.com]cheap vibram five fingers[/url]
[url=http://www.vibramfivefingerscheaps.com]vibram five fingers cheap[/url]
[url=http://www.vibramfivefingerscheaps.com/vibram-five-fingers-kso.html]vibram five fingers kso[/url]
[url=http://www.vibramfivefingerscheaps.com/vibram-five-fingers-classic.html]vibram five fingers classic[/url]
[url=http://www.vibramfivefingerscheaps.com/vibram-five-fingers-bikila.html]vibram five fingers bikila[/url]
[url=http://www.vibramfivefingerscheaps.com]vibram five fingers sale[/url]
[url=http://www.discountoakleysunglassescheap.com]cheap oakley sunglasses[/url]
[url=http://www.discountoakleysunglassescheap.com]discount oakley sunglasses[/url]
[url=http://www.discountoakleysunglassescheap.com]Oakley Photochromic Sunglasses[/url]
[url=http://www.discountoakleysunglassescheap.com]Oakley Limited Editions Sunglasses[/url]
[url=http://www.discountoakleysunglassescheap.com]oakley women sunglasses[/url]
[url=http://www.discountoakleysunglassescheap.com]oakley men sunglasses[/url]
[url=http://www.discountoakleysunglassescheap.com]wholesale oakley sunglasses[/url]
[url=http://www.discountoakleysunglassescheap.com/oakley-sport-sunglasses.html]Oakley Sport Sunglasses[/url]
[url=http://www.discountoakleysunglassescheap.com]oakley sunglasses cheap[/url]
Hot sunmmer coming, why not choose a pair [url=http://www.vibramfivefingerscheaps.com/]vibram five fingers shoes[/url] with [url=http://www.discountoakleysunglassescheap.com/]cheap Oakley Sunglasses[/url] with [url=http://www.vibramfivefingerscheaps.com/]cheap vibram five fingers shoes[/url] do water play. [url=http://www.vibramfivefingerscheaps.com/vibram-five-fingers-kso.html/]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
http://www.beatsheadphonesprice.org/
(10-Aug-12 10:37)  Posted by cheap gucci belts
[url=http://www.godealchina.com/wholesale/Gucci-Clothing-256_p1.html]Cheap Gucci Clothing[/url]
[url=http://www.godealchina.com/wholesale/Louis-Vuitton-Shoes-249_p1.html]Cheap Louis Vuitton Shoes[/url]
[url=http://www.godealchina.com/wholesale/Yves-Saint-Laurent-Clothing-309_p1.html]Cheap YSL T Shirts[/url]
[url=http://www.annydiscount.com/wholesale/Gucci-Shoes-55_p1.html]Cheap Gucci Shoes[/url]
[url=http://www.annydiscount.com/wholesale/Louis-Vuitton-Apparel-64_p1.html]Cheap Louis Vuitton Clothing[/url]
[url=http://www.annydiscount.com/wholesale/Prada-Shoes-92_p1.html]Cheap Prada Shoes[/url]
[url=http://www.chiclvshoes.com/shop/Yves-Saint-Laurent-Mens-T-shirts-154_p1.html]Cheap YSL T Shirts Men[/url]
[url=http://www.chiclvshoes.com/shop/Armani-Mens-Watches-193_p1.html]Cheap Armani Watches[/url]
[url=http://www.guccishoeshive.com/shop/belts-81_p1.html]Cheap Louis Vuitton Belts[/url]
[url=http://www.guccishoeshive.com/shop/t-shirts-
(29-Aug-12 4:32)  Posted by caoch outlet online
http://www.coachoutletonlinestoref.com coach outlet online
http://www.coachoutletonlineusmall.com coach outlet online
http://www.coachoutletusaonlinemall.com coach outlet
http://www.coachoutletonline12.com coach outlet

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













(sitemap)