2

I have searched all over the web and found different ways of closing a PhoneGap App. I tested all of them and none work. At least on Android.

Question:

Is it possible (By Feb 2014) to have a close button in a PhoneGap App on Android?

Thanks

This doesn't work:

function CloseApp() {

if (confirm('Close this App?')){

   if (navigator.app) {
        navigator.app.exitApp();
   }else if (navigator.device) {
        navigator.device.exitApp();
    }
}

}

Abraham Petit
  • 241
  • 1
  • 10

3 Answers3

1

Is

navigator.app.exitApp() 

really killing/closing the android app with phonegap?

I use cordova and have the same issue. Above mentioned code is just putting the app into background - I checked the running tasks (android task manager) after above code got executed by the app.

walt
  • 101
  • 5
  • It is really closing the app. It shows however in your recent app view on some devices. You can see that it really closes when you start the app again after closing, the splash screen will be shown. – Ricconnect Jan 19 '15 at 15:53
0

I am confused on why you want a button to close the app. Android already has a back button when clicked enough times will take the user back to the phone's main screen. There is also a home button that takes the user out of an app. Once, out of the app the user can "kill" the app through a task manager.

ejwill
  • 141
  • 8
0
navigator.app.exitApp() 

works and I use it in all my cordova apps. Check the rest of your code.

As ejwill said, having a "close" button is a bad idea. On Android I call exitApp when the user is the home page of my app and he presses the backbutton:

function onDeviceReady() {
    document.addEventListener("backbutton", onBackKey, false);
}


function onBackKey( event ) {
    var l = window.location.toString();
    var parts = l.split('#/');  // this works only if you are using angularjs
    var page = parts[1];
    if (page == 'home') {
        navigator.app.exitApp();
    } else {
        // do something else... one option is:
        navigator.app.backHistory();
    }
}

My 2c.

Sergio Morstabilini
  • 2,035
  • 21
  • 28