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
Contributor
carll70
Posts: 32
Registered: ‎10-21-2012
My Device: 9900
Accepted Solution

Post Global Event

Hello.  Looking for some insight on posting / listening for global events.  Wanting to update the text of a labelfield following smsSendListener() sendMessage.  Little confused about how this is done.  When executing ApplicationManager.getApplicationManager().postGlobalEvent, does the long value need to be the value of the smsSendListener() object?  At that point I assume I listen for that long value.  Is smsSendListener passed as an object I can reference based on the long value when listening for it?  I've review sample from http://supportforums.blackberry.com/t5/Java-Development/Global-Events-and-Global-Event-Listeners/ta-... as well as http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/system/GlobalEventListener.htm... and http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/system/Application.html#addGlo...).  Can anyone point me to something that may offer a little more guidance into this working?  Thank you.

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

Re: Post Global Event

Have a look at the samples provided by the ApplicationManager class:

http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/system/ApplicationManager.html

 

You 'fire' a long value, but associated with that long value you send 2 ints and 2 objects.  In your case for example, you could send the text you want to use to update the Field and the Field you want to be updated.  The long value should be unique.  Then in the listener, you must wait for the long value.  When a long value arrives, you can cast the objects that come with it to whatever you want, then perform an action - in your case update the text field.   

 

I hope this is enough.

Contributor
carll70
Posts: 32
Registered: ‎10-21-2012
My Device: 9900

Re: Post Global Event

Thank you, Peter.  Can the send and listen not be in the same class?  Wondering why this isn't working:

 

public class MyApp extends UiApplication implements GlobalEventListener {

	private MainScreen mainScreen;
	
	public static void main( String[] args ) {
		final MyApp theApp = new MyApp();
		theApp.enterEventDispatcher();
	}

	public MyApp() {
		mainScreen = new MainScreen(); 
		mainScreen.setTitle(new LabelField("Global Event Firing")); 
		MenuItem fireEvent = new MenuItem("Fire Global Event", 20, 20) {  
			public void run() {    
				ApplicationManager.getApplicationManager().postGlobalEvent(0xba4b84944bb7429eL);
			}
		};       
		mainScreen.addMenuItem(fireEvent);  
		pushScreen(mainScreen);  
	}

	public void eventOccurred(long guid, int data0, int data1, Object object0, Object object1) {
		if (guid == 0xba4b84944bb7429eL) {  
			UiApplication.getUiApplication().invokeLater(new Runnable() {                
				public void run()                { 
					Dialog.alert("Event was fired and acknowledged.");
				}         
			});  
		}  
	
	}
	
}

 

 

Contributor
carll70
Posts: 32
Registered: ‎10-21-2012
My Device: 9900

Re: Post Global Event

Looks like I forgot addGlobalEventListener(this);.  Working now.  Thanks.

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

Re: Post Global Event

No probs and I guess we would all like confirmation that this has resolved your problem?

Contributor
carll70
Posts: 32
Registered: ‎10-21-2012
My Device: 9900

Re: Post Global Event

Posting / listening for global events is working great!  Really appreciate everything.