6

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

Yagi
  • 511
  • 2
  • 5
  • 19
  • Is `navigator.app.exitApp()` throwing any errors? First place I would look is to make sure that `` is in your `plugins.xml` file. – Lyle Pratt Jan 08 '12 at 00:06
  • No, there are no any errors I got. When I click the button, there is no response, whereas I place navigator.app.exitApp() on my action button to exit the application but it didn't response – Yagi Jan 09 '12 at 07:48
  • Would it be possible to upgrade the phonegap version? It seems it gives some problems in old versions (http://community.phonegap.com/nitobi/topics/how_to_exit_from_the_phonegap_app_on_android_and_ios) – davids Aug 09 '12 at 12:38
  • How about stop using ST1 and work in ST2? – Rob Aug 13 '12 at 06:58

4 Answers4

10

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(); 
   }
}
Simona Adriani
  • 561
  • 6
  • 16
Saurabh Android
  • 668
  • 8
  • 15
1

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.

gcatalfamo
  • 243
  • 2
  • 14
0

See this

You need to add a listener event for the backbutton and associate a function.

It would be a good idea to update your phonegap/cordova version to the latest build and use the code provided above.

Community
  • 1
  • 1
Keshav
  • 171
  • 1
  • 11
0

This code like a charm:

Ext.Msg.confirm("Close app?.", 'Close app', function (btn) {
  if (btn == 'yes') {
    navigator.app.exitApp();
  }
});
Victor Azevedo
  • 537
  • 4
  • 7