admin管理员组

文章数量:1402826

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

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

Share Improve this question asked Dec 16, 2012 at 16:05 Dimensional SysDimensional Sys 4981 gold badge6 silver badges21 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 7

You can handle back button event like this in your code

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

I suggest you set the (Android specific) exitOnClose property on false when creating the new window:

http://docs.appcelerator./titanium/latest/#!/api/Titanium.UI.Window-property-exitOnClose

exitOnClose : Boolean CREATION-ONLY

Boolean value indicating if the application should exit when the Android Back button is > > pressed while the window is being shown.

You can only set this as a createWindow({...}) option. Setting it after window creation > has no effect.

StatusMain.js

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

That should do the trick. Although the default value is false, it seems that your issue has something to do with that. I remend experimenting with settings this property to true/false.

Word of advise, you should also test your app on a device if you haven't done so already. My experience with the Android emulators is rather inconsistent at some points.

StatusMain is a lightweight window. It doesn't create new Android activity, instead it shares with SignIn window activity. That's why your app closes when press back button. You need to create a heavyweight window to (specify fullscreen or navBarHidden properties) StatusMain window.

Set the modal property for the new window to true.

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

本文标签: javascriptWhy APP is exiting on back button TitaniumStack Overflow