Android Pause/Resume App Events Not Firing

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

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;
};

— asked 1 year ago by Eli Mor
0 Comments

1 Answer

pause and resume are only for iOS. Wont work on Android.

— answered 1 year ago by Minh Nguyen
answer permalink
7 Comments
  • Thanks for the response. Any workaround you know of?

    — commented 1 year ago by Eli Mor

  • Try this

    var activity = Ti.Android.currentActivity;
    ['create', 'destroy', 'pause', 'resume', 'start', 'stop'].forEach(function(e) {
        activity.addEventListener(e, function() {
            Ti.API.info((new Date()) + " Activity: " + e + " HIT!");
        })
    });

    — commented 1 year ago by Minh Nguyen

  • And you need to set exitOnClose: false when create your windows.

    Check this guide for exitOnClose.

    — commented 1 year ago by Minh Nguyen

  • Show 4 more comments

Your Answer

Think you can help? Login to answer this question!