Titanium.App.exit for Android

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?


3 Answers

  • Use finish() method for current activity:

    var activity = Titanium.Android.currentActivity;

    Works for 1.5+: http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Android.Activity-object.html

    — answered 5 years ago by David
    • this method worked for me, thanks!


      — commented 4 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',
          // delayed actitivy finish so that app closes
          var timer = setTimeout(function() {
              var activity = Titanium.Android.currentActivity;

      — commented 4 years ago by Torsten Stelling
  • In the first window you create in app.js add this property:

    exitOnClose: true

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

      — commented 2 years 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