Android - How to Detect Application In Background and Exit
I am wondering if there is way to detect when an Android application is sent to the background using the home button.
Also, is it possible to exit the application when it is sent to the background?
Are both these possible in Titanium?
3 Answers
-
You can use the exitOnClose property on your main window. This will close the app when the back button is pressed. I do not believe there is anyway to handle this when the home button is pressed. You can try to look the onPause events to trigger to close the window that has the exitOnClose property. This will close your App but not easy to do given Android's activity lifecycle.
-
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.
-
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.