0

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

mohsin.mr
  • 498
  • 1
  • 6
  • 21

4 Answers4

7

You can handle back button event like this in your code

window.addEventListener('android:back', function(){
    // close your current window
});
Hasnain
  • 461
  • 2
  • 11
2

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

http://docs.appcelerator.com/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 recommend 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.

Robin van Baalen
  • 3,632
  • 2
  • 21
  • 35
1

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.

0

Set the modal property for the new window to true.

function StatusMain(global_vars) {
        var self = Ti.UI.createWindow({
        modal: true
    });
    return self;
}
Sakhr
  • 186
  • 1
  • 9