Titanium Community Questions & Answer Archive

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

Cancel Titanium.EXIT event

I use the event Titanium.EXIT to clean up before my Desktop application exits. I'd like to cancel the exit if e.g. the user has unsaved data and chooses not to exit.

Titanium.API.addEventListener(
Titanium.EXIT,
  function() {

 // How to intercept exit here ?

});

Any ideas how to cancel the exit? The documentation mentions "an event handler may cancel the EXIT event by calling preventDefault or stopPropagation on it" but
calling Titanium.EXIT.preventDefault() or Titanium.EXIT.stopPropagation() has no effect. I also tried the APP_EXIT event because I don't really know what's the difference.

Any ideas? Should be an easy task but I'm stuck here.

— asked June 13th 2010 by Stefan Washietl
  • desktop
  • exit
0 Comments

4 Answers

  • You need to pass an 'event' variable into the function:

    Titanium.API.addEventListener(
    Titanium.EXIT,
    function(event) {

    event.stopPropagation();

    });

    — answered July 18th 2010 by behnv behj
    permalink
    0 Comments
  • My application is closed and navigate to home screen using setting both [exitOnClose:true; OR Titanium.Android.currentActivity.finish();] but at settings->manage application->running it showing my application icon running list at back end so how to resolve this issue?I want when my application is gets closed at a time i want to stop back end running process also.please help me out.

    — answered November 19th 2011 by Fernan Delgado
    permalink
    1 Comment
    • Fernan,

      Did you try what Behnv posted above your post ?

      — commented November 21st 2011 by Alan DuBoff
  • I am talking about mobile application not for desktop application Alan.Anyway thanks a lot for quick replay.

    — answered November 22nd 2011 by Fernan Delgado
    permalink
    0 Comments
  • No i am using code:

    var dlg = Titanium.UI.createAlertDialog({ title:'Logout:', message:'Are you want to close application ?', buttonNames: ['Yes','No'] });

    dlg.addEventListener('click', function(ev) { if (ev.index == 0) {

        var intent = Ti.Android.createIntent({
        action: Ti.Android.ACTION_MAIN
    
    });
    
    intent.addCategory(Ti.Android.CATEGORY_HOME);
    Ti.Android.currentActivity.startActivity(intent);
    var activity = Titanium.Android.currentActivity;
    activity.finish();
    

    } else if (ev.index == 1) { }

    });

    dlg.show();

    Now through this code my screen is navigate to home screen but back end running process for my application is still running. So how to stop this back end running process for my application.You can see running application list at HomeScreen->Settings->Applications->Manage Application->running(second tab).

    So i have to end my application running process at backend when application gets logout. Any help.

    — answered November 22nd 2011 by Fernan Delgado
    permalink
    1 Comment
    • Oh, you marked your question as desktop…

      — commented November 22nd 2011 by Alan DuBoff
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.