I've seen this question in other posts, but these don't work for me. When the app is in focus, i'm clicking the home button on the android emulator and the only events that show in the console are about the window losing focus. I then bring bring the app back (launching it again from the dashbored), and no events register in the console the app was resumed. I'm using TabGroup, so I might be missing something. Any advice is appreciated!
- Titanium 1.8.1
- Android 2.2 + Emulator
- Mac OSX 10.7.2
Ti.App.addEventListener('resume', function() { Ti.API.info('App Resumed'); }); Ti.App.addEventListener('pause', function() { Ti.API.info('App Paused'); });
The full test code:
app.js
// app.js //add a single variable to the global scope to which we may choose to //intentionally add items to var globals = {}; //create a private scope to prevent further polluting the global object (function() { var AppTabGroup = require('ui/AppTabGroup').AppTabGroup, Window1 = require('ui/Window1').Window1, Window2 = require('ui/Window3').Window2; //create our global tab group globals.tabs = new AppTabGroup({ title : 'Todo', icon : 'KS_nav_ui.png', window : new Window1({ title : 'Window1', backgroundColor : '#fff', }) }, { title : 'Done', icon : 'KS_nav_views.png', window : new Window2({ title : 'Window2', backgroundColor : '#fff', }) }); globals.tabs.open(); Ti.App.addEventListener('GUI.SwitchTab', function(e) { Ti.API.info('activetab:' + globals.tabs.getActiveTab()); Ti.API.info('app listener fired with:' + e.tab); globals.tabs.setActiveTab(globals.tabs[e.tab]); }); Ti.App.addEventListener('resume', function() { Ti.API.info('App Resumed'); }); Ti.App.addEventListener('pause', function() { Ti.API.info('App Paused'); }); })();Window1.js
// Window1.js exports.Window1 = function(args) { var self = Ti.UI.createWindow({ windowSoftInputMode : Ti.UI.Android.SOFT_INPUT_STATE_ALWAYS_HIDDEN, navBarHidden : true, exitOnClose : true, }); var switchButton = Ti.UI.createButton({ title : 'Switch to Tab 2', width : '300dp', height : '40dp', top : '80dp' }); switchButton.addEventListener('click', function() { Ti.App.fireEvent('GUI.SwitchTab', { tab : 2 }); }); self.add(switchButton); self.addEventListener('blur', function() { Ti.API.info('Window1 blured'); }); self.addEventListener('focus', function() { Ti.API.info('Window1 focus'); }); Ti.App.addEventListener('resume', function() { Ti.API.info('Window1 Resumed'); }); Ti.App.addEventListener('pause', function() { Ti.API.info('Window1 Paused'); }); return self; };Window3.js
// Window3.js exports.Window2 = function(args) { var self = Ti.UI.createWindow({ fullscreen : false, }); var switchButton = Ti.UI.createButton({ title : 'Switch to Tab 1', width : '300dp', height : '40dp', top : '80dp' }); switchButton.addEventListener('click', function() { Ti.App.fireEvent('GUI.SwitchTab', { tab : 1 }); }); self.add(switchButton); self.addEventListener('blur', function() { Ti.API.info('Window2 blured'); }); self.addEventListener('focus', function() { Ti.API.info('Window2 focus'); }); Ti.App.addEventListener('resume', function() { Ti.API.info('Window2 Resumed'); }); Ti.App.addEventListener('pause', function() { Ti.API.info('Window2 Paused'); }); return self; };
1 Answer
Your Answer
Think you can help? Login to answer this question!