Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use navigator.app.exitApp() to exit application in phone gap?

I have an application built using sencha-touch & phonegap but I don't know how to add exit/stop function to exit the application. After looking arround in google and other sites I got clue to use navigator.app.exitApp() but it didn't work.

How can I solve this?

Note : I'm using - phonegap 1.3 - sencha touch 1.1 - Galaxy tab

Thanks in advance

like image 603
Yagi Avatar asked Jan 05 '12 06:01

Yagi


2 Answers

Please try following code, it is working fine in my app:

document.addEventListener("exitButton",function(){ 

    navigator.notification.confirm(
           'Do you want to quit', 
           onConfirmQuit, 
           'QUIT TITLE', 
           'OK,Cancel'  
    );

}, true);

function onConfirmQuit(button){
   if(button == "1"){
     navigator.app.exitApp(); 
   }
}
like image 159
Saurabh Android Avatar answered Sep 22 '22 12:09

Saurabh Android


Put something like this in the HTML file:

<a href="#" onClick="closeMeNow();" data-role="button">Close App</a>

That links to a function like this in your JS file:

function closeMeNow() {
    navigator.app.exitApp();
}

I know the syntax is more JQM than Sencha, but since the concept is basically the same you can just edit where is needed.

like image 41
gcatalfamo Avatar answered Sep 22 '22 12:09

gcatalfamo