Titanium.App.exit for Android

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

I'm developing a simple little app for my Android phone.

My BACK button doesn't work as it should (it SHOULD exit the app when I am on the main menu, wich i've put on app.js) but it only zapps between former open windows I've been on within the app. The ideal solution would be to get this button to work, but how?

The other solution I thought of, was the Titanium.App.exit wich unfortunately seems only to work for Desktop apps?

I want to put this "exit button" in an Android.OptionMenu in an eventlistener.

Anyone able to help me, either to get the Back button to work, or some other way to exit my app? Please?

/j

3 Answers

Use finish() method for current activity:

var activity = Titanium.Android.currentActivity;
activity.finish();
Works for 1.5+: http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Android.Activity-object.html

— answered 4 years ago by David
answer permalink
2 Comments
  • this method worked for me, thanks!

    Lode

    — commented 3 years ago by lode schoors

  • When you want to close an unwanted window like me, this snippet helped me a lot.

    I added it on a click which opens a new tabgroup. The first window (mainWindow) will not be shown anymore when going back. The screen will go black and the app will be closed after that.

    I added this, since a tabgroup does not support ExitOnClose.

    mainWindow.addEventListener('focus',function(event) {
        var blackView = Titanium.UI.createView(Theme.create(THEME.STARTSCREEN.TOUCHVIEW,{
            backgroundColor: '#666',
        }));
        mainWindow.add(blackView);
        // delayed actitivy finish so that app closes
        var timer = setTimeout(function() {
            clearTimeout(timer);
            var activity = Titanium.Android.currentActivity;
            activity.finish();
        },500);
    });

    — commented 3 years ago by Torsten Stelling

In the first window you create in app.js add this property:

exitOnClose: true

— answered 4 years ago by Doug Handy
answer permalink
1 Comment
  • This is the correct answer, the one before it has nothing to do with the question

    — commented 12 months ago by Oday Maleh

Joar

You need to use exitOnClose and a property to make the window heavyweight, such as navBarHidden. For example:

var window = Ti.UI.createWindow({
 backgroundColor: '#cccccc',
 exitOnClose: true,
 navBarHidden: false
});

Your Answer

Think you can help? Login to answer this question!