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: 1,548
Registered: ‎07-14-2008
My Device: Z10
My Carrier: Fido

Re: how to get choice from Global pushed screen!?

sorry instead of


ui.pushGlobalScreen(screen, 1, UiEngine.GLOBAL_QUEUE);



ui.pushGlobalScreen(screen, 1, UiEngine.GLOBAL_MODAL);
Posts: 165
Registered: ‎10-04-2010
My Device: P'9982 & Z10
My Carrier: alfa Lebanon

Re: how to get choice from Global pushed screen!?

So after using what you said, this is the code I'm working with now:



 synchronized(Application.getEventLock()){    UiEngine ui = Ui.getUiEngine();
     	 Screen screen = new Dialog(Dialog.D_YES_NO, msg,
  	        Dialog.NO, Bitmap.getPredefinedBitmap(Bitmap.EXCLAMATION), Manager.VERTICAL_SCROLL);
 		 NotificationsManager.triggerImmediateEvent(ID, 0, null, null);
     	 ui.pushGlobalScreen(screen, 1, UiEngine.GLOBAL_MODAL);   	    
 	    	if ( ((Dialog)screen).getSelectedValue() == Dialog.YES)
 	    		NotificationsManager.cancelImmediateEvent(ID, 0, null, null);
 	    		return true;
 	    		NotificationsManager.cancelImmediateEvent(ID, 0, null, null);
 	 			return false;



When I use:  UiEngine.GLOBAL_QUEUE, the code keeps running and doesn't wait for what the user choses.

When I use:  UiEngine.GLOBAL_MODAL, I get this error: "pushGLobalSCreen(modal) called by a non-event thread"


This a function that can be called either when a user clicks a button or according to a timer that the users can set. When the user clicks the button it works fine with GLOBAL_MODAL but when it's triggered by the timer I get the above error. I tried researching the error but couldn't really find help on what it real means or how to fix it.

Posts: 19,628
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to get choice from Global pushed screen!?

[ Edited ]

The code you have here is intended to be used from a Background Thread with no Ui component.  I suspect you do not need it in this case. 


When called from a Button, you already have the Event Thread and you know your application is in the foreground, so in this situation you should just issue the Dialog.  This does not need to be a global screen.  Nor does it need to have any notifications associated - the user can see the screen. 


When called from the Timer, you are NOT running on the Event Thread.  In addition, you don't know if your application is in the foreground.  And you may or may not want it to come to the foreground. 


However it seems you want a single function that you pass a String to and it returns with either true or false.  So I would code something like this:


final Dialog d = new Dialog...

// I'm not convinced that calling this a Dialog prevented the screen appearing Globally as you suggested.

// So I would identify it as a Dialog

if ( Application.isEventDispatchThread() ) {

// We have the Event Thread, can just show the Dialog


} else {

// running in background

UiApplication.getUiApplication().invokeAndWait(new Runnable() {

public void run() {

NotificationsManager.triggerImmediateEvent(ID, 0, null, null);

UiApplication.getUiApplication().pushGlobalScreen(d, 1, UiEngine.GLOBAL_MODAL);  

NotificationsManager.cancelImmediateEvent(ID, 0, null, null);



return ( d.getSelectedValue() == Dialog.YES );


Not sure this will work, certainly probably won't compile, but you get the idea....