Titanium Community Questions & Answer Archive

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

Close application with onclick

Hello,

I got an AlertDialog, when a users clicks on 'Ok'. My application should shutdown. Does anybody knows how to do this?

Greetings,
Jacob

— asked October 22nd 2010 by Jacob van Dam
  • android
  • application
  • close
  • exit
  • shutdown
0 Comments

4 Answers

  • There is a property for the createWindow method on android called "exitOnClose". Set it to true and then close the window.

    details: http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.Window-object

    Otherwise I don't believe there is a way to programatically 'close' the app – other than forcing a crash.

    — answered October 22nd 2010 by Kevin McGrath
    permalink
    3 Comments
    • This doesn't work either. I added this already, but my guess is that a event doesn't use exitOnClose.

      — commented October 22nd 2010 by Jacob van Dam
    • exitOnClose property set to true on a window correctly exited the app when I closed the window, thanks for this little trick! Otherwise there would be no way to exit an app, which is control a developer should have, despite what Don claims.

      — commented June 8th 2011 by Justin Toth
    • You and I may think a developer should have that option, but Apple in their infinite wisdom does not agree. They explicitly prohibit you from having that capability and insist it should be up to the user alone to make that decision. It doesn't matter we may have legitimate reasons for wanting to do that – Apple dictates what can be done in iOS so you aren't going to get there from here with iOS. Assuming you don't want to force a crash. :)

      In Android, the proper way to do it is the window "exitOnClose" property.

      — commented June 8th 2011 by Doug Handy
  • I would also like to use this (on both iPhone and Android). Did anyone found a solution already?

    — answered October 25th 2010 by Peter Griffin
    permalink
    0 Comments
  • That's not typical Android app behavior, but try calling close() on the initial window.

    — answered October 22nd 2010 by Don Thorp
    permalink
    1 Comment
    • Well i got the Appcelerator logo when i use that. (loading screen)

      — commented October 22nd 2010 by Jacob van Dam
  • var activity = Titanium.Android.currentActivity;
    activity.finish();

    — answered January 19th 2013 by sergio ibanez
    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.