Search code examples
javascriptandroidbuttontitaniumback

Why APP is exiting on back button Titanium


app.js

if (osname === 'android') {
    Window = require('ui/handheld/android/SignIn');
}
else {
    Window = require('ui/handheld/SignIn');
}

new Window().open();

SignIn.js

function SignIn() {
    var self = Ti.UI.createWindow();
    //Some design and sign-in validation code
    ...
    var StatusMain = require('/ui/handheld/android/StatusMain');
    new StatusMain(global_vars).open();
    return self;
}

StatusMain.js

function StatusMain(global_vars) {
    var self = Ti.UI.createWindow();
        return self;
}

On StatusMain.js, screen When I click on device's back button APP exits instead of going back on SignIn.js screen

Any help will be highly appreciable!

Thanks in advance,

Mohsin


Solution

  • You can handle back button event like this in your code

    window.addEventListener('android:back', function(){
        // close your current window
    });