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?

/j

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

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

      Lode

      — 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',
          }));
          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 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
    permalink
    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
    permalink
    0 Comments
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.