Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Posts: 326
Registered: ‎02-02-2009
My Device: Not Specified

how to promt from thread

I want to promt like

int replay = Dialog.ask(Dialog.D_YES_NO,"do processing",Dialog.NO);

the code work inside the thread , so i can not do this , an exception : java.lang.RuntimeException: pushModalScreen called by a non-event thread   arrises?


how to promt from thread?

Please use plain text.
Posts: 220
Registered: ‎09-09-2008
My Device: Bold 9780
My Carrier: Telstra AU

Re: how to promt from thread

Hi what u need to do is access the UiThread by the following:




UiApplication.getUiApplication().invokeLater(new Runnable(){ public void run(){ //Dialog.alert("blalbla"); } });


I hope the syntax is all correct as i just wrote this of top of my head.....



Follow me on twitter: twitter.com/paul.haenel

If your issue is resolved, please mark this thread as solved.

Set the "Solution" mark on the post which contains the answer to your question.
Please use plain text.
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to prompt from thread

Just to confirm what paulhaenal has said, the issue here is that the Blackberry ensures that only one thing is updating the UI at one time using what it calls the 'Event Thread'.  You can see more about it here:


What is the Event Thread?



Your background thread needs to grab this, and you have two options:

a) Either you pass a Runnable object to the EventThread to run, using invokelater (which is what is in the example), or invokeAndWait

b) You can grab the EventLock yourself


These options are further explained here:


User Interface Coding Tips



Now in your case, you actually want to get some input from the user, so if you are just going to ask a question and get the response, then the best option for you must be to grab the Event Lock, i.e. put your code inside a:


synchronized(Application.getEventLock()) {



block.  Personally I try to avoid doing this, and I've never coded an example quite like yours, but I think you just do the following:


int reply = -Dialog.NO;

synchronized(Application.getEventLock()) {

reply = Dialog.ask(Dialog.D_YES_NO,"do processing",Dialog.NO);



I'm interested to know if this works.  If not, then you should probably use invokeAndWait.. 

Please use plain text.