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: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Dialog.show() not showing

I have not tried this, nor coded a workaround, so perhaps what I am about to tell you is wrong.  If so I will have a go at coding.  But hopefully the following is correct.


The issue is the Event Thread and this bit of code and the fact that this code is being run in a keyDown method:


Dialog d = new Dialog("This is a dialog.",

new Object[0], new int[0], 0, Bitmap.getPredefinedBitmap(Bitmap.INFORMATION));


try { Thread.sleep(3000); }

catch (java.lang.InterruptedException e) {}



show is not modal so this will schedule a display on the Event Thread.  This means it waits until the Event Thread has finished doing whatever it is currently doing before the Dialog is displayed. 


However at this time, the Event Thread is busy processing the keyDown method.  So until the keyDown method completes, the Dialog will not be displayed. 


Now the keyDown method is stalled for 3 seconds and then closes the Dialog.  So before it is even displayed the Dialog is closed.  So you will never see it.


And coding a sleep on the Event Thread is a bad idea.  It will hold up all Event processing, like menu key presses etc, for your application.  Your application will appear dead.


If you have some text that you need displayed just for a period of time, look at Status.show(...).


If Status.show does not do it for you, tell us your requirements and we will suggest coding alternatives. 


Hope this helps



New Developer
Posts: 18
Registered: ‎09-03-2008
My Device: Not Specified

Re: Dialog.show() not showing

Hi Peter,


Yes, you're of course right that sleep()ing on the event thread is a bad idea, it was just done here because it was the simplest way to demonstrate the problem.


And thank you! Your hypothesis is correct. The problem is indeed that the whole event thread is stalled, so breaking the Dialog.show() and close() out to a separate thread solved the problem.


Thanks again,