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.
4 Answers
-
You need to pass an 'event' variable into the function:
Titanium.API.addEventListener(
Titanium.EXIT,
function(event) {event.stopPropagation();
});
-
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.
-
I am talking about mobile application not for desktop application Alan.Anyway thanks a lot for quick replay.
-
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.