Minimize to tray only works once

You must Login before you can answer or comment on any questions.

I'm trying to make my application minimize to the tray on Windows. I am using the following code which works, but I can only restore from the tray after the first time the application is minimized. The second time I minimize and try to restore from the tray, nothing happens when clicking the tray icon. I'm sure I've done something stupid, but can not find what it is. Could someone help me out?

function initTray() {
    var window = Titanium.UI.getCurrentWindow();
    Titanium.UI.getCurrentWindow().addEventListener(Titanium.MINIMIZED, function(event) {
        window.hide();
        tray = Titanium.UI.addTray("app://logo.png", function(evt) {
            if (evt.getType() == 'clicked') {
                Titanium.UI.clearTray();
                window.show();
                window.unminimize();
            }
        });
    });
}

— asked 2 years ago by Jeremy Zongker
1 Comment
  • For some reason the window doesn't seem to pop back to the front of the window stack it comes back up but its hidden still for me.

    — commented 1 year ago by Michael Fasani

2 Answers

This worked for me...

var window = Titanium.UI.getCurrentWindow();
Titanium.UI.getCurrentWindow().addEventListener(Titanium.MINIMIZED, function(event) {
    window.hide();
});
var tray = Titanium.UI.addTray("app://images/icon16.png", function(evt){
    if (evt.getType() == 'clicked') {
        if (!currentWindow.isVisible()){
            window.show();
                window.unminimize();
        }
    }
});

last two codes worked but not functioning very well. because variable window. use below code var current_window = Titanium.UI.getCurrentWindow(); Titanium.UI.getCurrentWindow().addEventListener(Titanium.MINIMIZED, function(event) { current_window.hide(); });

tray = Titanium.UI.addTray("app://default_app_logo.png", function(evt) { if (evt.getType() == 'clicked') { if (!current_window.isVisible()) { current_window.show(); } } });

Your Answer

Think you can help? Login to answer this question!