views:

296

answers:

1

I have an AIR application with a system tray icon. When clicked it shows and activates the app. This is working as expected when the app is hidden (docked), however if I select another application so my app is in the background clicking on the system tray icon does nothing.

Oddly I also have a contextual menu on the system tray icon, which has an option to restore, this calls the same event handler as ScreenMouseEvent.CLICK, yet works.

I expect it's something to do with the contextual menu changing the focus, perhaps it's a bug in how AIR works with the system tray, perhaps it's just something I'm missing. Would be good to know if that's the case.

Thanks in advance

Rob

+1  A: 
//instead of just calling
activate();

//call
nativeApplication.activate()

//or even better
nativeApplication.activate(nativeWindow);

Update based on OP's input: if you have multiple windows open for the application, use:

nativeApplication.activate(nativeApplication.openedWindows[0]);

If you are not in the main WindowedApplication class, you can use the static property NativeApplication.nativeApplication to get a reference to the singleton object.

WindowedApplication.activate()

Activates the underlying NativeWindow (even if this application is not the active one).

NativeApplication.activate(window:NativeWindow = null)

Activates this application. If the operating system allows activation, then the specified window is activated and brought to the desktop foreground; that is, in front of the windows of other applications. (If the window parameter is null, then a visible window of this application is activated.)

livedocs is not clear on why this is happening. It says activate() activates the underlying native window - one would expect it to be brought to the front when it is activated, but that's not happening.

Amarghosh
This worked:NativeApplication.nativeApplication.activate(NativeApplication.nativeApplication.openedWindows[0]);Can you explain why Application.application.nativeWindow.activate(); only worked in some cases?
robmcm
Thanks for the extension. I guess being overly explicit is a good thing anyway.
robmcm
I also had a similar problem with window notification. Again being overly explicit about which window fixed it.
robmcm
I believe the root issue causing the behavior is that:1) The application must be active before you can call activate on any of its windows2) The application (as a whole) is activated either when you explicitly call nativeApplication.activate() or when you click on application UI (such as a window or context menu).Clicking on the system tray icon doesn't activate the application, so your call to nativeWindow.activate() will do nothing. However, clicking on the context menu that pops up from the try icon *does* activate the app, which is why your call worked then.
Chris R