Welcome!

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

Reply
Developer
pav52
Posts: 46
Registered: ‎12-01-2009
My Device: Not Specified

How to create a simple blocking Dialog alert?

Hey guys,

 

To be able to invoke alerts from just about anywhere (not only the event thread), I've created this helper method:

 

 

	public static void displayAlert(final String text)
	{
		UiApplication.getUiApplication().invokeAndWait(new Runnable()
		{
				public void run()
				{
					synchronized(Application.getEventLock())
					{
						//Dialog.alert(text);
						Dialog.ask(Dialog.D_OK, text);
					}
				}
		});
	}

 

However, it appears that invokeAndWait does not actually wait for the user to respond to the Dialog, but rather displays the dialog and moves on.

 

 

How can the above be modified to block until the user responds before returning from my displayAlert function?

 

Thanks in advance :-)

 

Developer
Sakberry
Posts: 248
Registered: ‎11-23-2009
My Device: Not Specified

Re: How to create a simple blocking Dialog alert?

hi

 

 

I think when you ask the user for something using Dialog.ask you should also make a provision to accept the uers input. I think thats where you might be missing out.

 

Try something like this:

 

//Confirm deletion
            int ans= Dialog.ask(Dialog.D_YES_NO,"Are You Sure you want to delete this Memo?",Dialog.NO);
            //if user selects yes then delete record
            if(ans==Dialog.YES)
            {

.....................

}

Hope it helps!

 

Saket

Developer
pav52
Posts: 46
Registered: ‎12-01-2009
My Device: Not Specified

Re: How to create a simple blocking Dialog alert?

Apparently, it blocks sometimes. This seems very odd.

 

Inside a FieldChangeListener.fieldChanged(...) on a button click, I have:

 

 

someFunction();
					
ScreenController.startScreen(new MainScreen1()); <-- custom

 

someFunction contains a ton of logic which has the potential for triggering ScreenController.displayAlert(...). These alerts are shown for a split second as ScreenController.startScreen() executes overwriting the alerts instead of waiting for the user to click OK on them.

 

 

Developer
ydaraishy
Posts: 562
Registered: ‎09-30-2009
My Device: Not Specified

Re: How to create a simple blocking Dialog alert?

How many threads do you have running, out of curiosity?

Developer
pav52
Posts: 46
Registered: ‎12-01-2009
My Device: Not Specified

Re: How to create a simple blocking Dialog alert?

ydaraishy: Around 5 :-)

 

I'm not sure what I did, but it's working consistently as it should now. I suspect I was just doing something weird and my trying to figure it out solved it.

 

 

Developer
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to create a simple blocking Dialog alert?

Good to hear it seems to be working.

 

Just a minor comment.  In your code it seems to me that the:

 

synchronized(Application.getEventLock())

 

is not needed.  The Runnable should be running on the Event Thread at that point anyway, so this is redundant.  Doesn't effect anything, I am just noting it for completeness.

 

Actually one more thing - if this is now solved, can you mark it as such?

 

Cheers