Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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?


— asked November 29th 2010 by Joar Ekendahl
  • android
  • back
  • button
  • mac
  • mobile

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 March 18th 2011 by David
    • this method worked for me, thanks!


      — commented June 28th 2011 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 September 27th 2011 by Torsten Stelling
  • In the first window you create in app.js add this property:

    exitOnClose: true

    — answered November 29th 2010 by Doug Handy
    1 Comment
    • This is the correct answer, the one before it has nothing to do with the question

      — commented December 17th 2013 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
    — answered November 29th 2010 by Paul Dowsett
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.