Inter application communication

I have an application HelloApp.

HelloApp has a menubar. On the menubar are
[login, logout, username, etc, etc]

login menuitem has two subitems
[login using google id, login using openid]

This is when my trouble starts -

when the user clicks on either of the login subitems,
HelloApp creates and attaches to itself a new window class Loginout.
Loginout creates an Embedded which would contain the google or openid login site.

When user successfully logs in, google userservice or openid service is told to redirect to application LoginoutApp.

I need LoginoutApp to access HelloApp to update its menubar so that
login item is setVisible to false,
logout item is setVisible to true,
username is set to the logged in user’s name.

The similar would need to happen when user clicks on logout. HelloApp instantiates a new Window class with an Embedded to google or openid logout site, which are directed to redirect to callback on LoginoutApp. LoginoutApp then needs to update the menubar of HelloApp to
set logout item visible to false,
set login item visible to true,
set username to “not logged in”.

Basically, the question is how to perform inter Application communication?

Answering my own question, this is how I did it.


	static public MyApplication getSynApp(Application a){
		Collection<Application>  apps = a.getContext().getApplications();
		
		for (Application app: apps){
			if (app instanceof MyApplication)
				return (MyApplication)app;
		}
		
		return null;
	}

Can you elaborate on this solution little more. As I have similar use case where I am talking to a third party Java application, which gets launched in a different browser when user clicks on a button or link. Now when the third party app calls back the main application window using javascript function. I need to put somewhere a callback function so that third party app can callback.