Titanium Community Questions & Answer Archive

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

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?

— asked September 21st 2011 by Tuan Nguyen
  • android
  • background
  • exit application
  • home button
0 Comments

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.

    — answered September 30th 2011 by Ben Bahrenburg
    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
    • your application get closed with back button press right? well back end running process means the backgroud service or the simple application process?

      — commented November 19th 2011 by Nikunj Sakhrelia
  • 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
    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.