How to exit from the phonegap app on Android and IOS?

  • 2
  • Question
  • Updated 4 years ago
Hi, I am trying to exit the phonegap application on IOS and Android. I have use below code : navigator.app.exitApp(); and navigator.device.exitApp(); but on them is working and get error like :TypeError: Result of expression 'navigator.device' [undefined] is not an object. at file:///android_asset/www/disclaimer.html:50

Is there ant straight forward solution to complete exit the phonegap app?
Photo of Shail

Shail

  • 21 Posts
  • 2 Reply Likes

Posted 8 years ago

  • 2
Photo of Andrew Lunny

Andrew Lunny

  • 1911 Posts
  • 199 Reply Likes
You can use navigator.app.exitApp() - I believe that's supported on Android.

On iOS, Apple does not allow apps to programmatically exit.
Photo of Red2678

Red2678

  • 255 Posts
  • 0 Reply Likes
Hi Andrew, "On iOS, Apple does not allow apps to programmatically exit." Is that still the case?
Photo of Andrew Lunny

Andrew Lunny

  • 1911 Posts
  • 199 Reply Likes
Yes, as far as I know.
Photo of Ivan Gonzalez

Ivan Gonzalez

  • 1 Post
  • 0 Reply Likes
Do not exit explicitly from an iOS app is strongly not recommended, but it is not forbidden if there is a good reason for it. (app feature not working or similar)
Photo of rohil patel

rohil patel

  • 1 Post
  • 0 Reply Likes
loda tari gaan thai che magaj ni maa chodi che tara code a toh
Photo of Shail

Shail

  • 21 Posts
  • 2 Reply Likes
Hi Andrew,

Thanks for quick reply.

I have already use the navigator.app.exitApp() - but it's give the undefined error on android.

is there any alternate solution?

Shail.
Photo of Andrew Lunny

Andrew Lunny

  • 1911 Posts
  • 199 Reply Likes
Are you sure deviceready has fired? And are you including phonegap.js on the page?
Photo of Shail

Shail

  • 21 Posts
  • 2 Reply Likes
Hi Andrew,

I have upgrade the phonegap version and problem solved.

Thanks a lot.

Shail.
Photo of axlsmit

axlsmit

  • 5 Posts
  • 0 Reply Likes
hi shail what is the phonegap version do you use?
i use 2.1 with phonegap build and navigator.app.exitApp() not work in ios

thanks.
Photo of axlsmit

axlsmit

  • 5 Posts
  • 0 Reply Likes
i use a iphone 3gs thanks
Photo of Red2678

Red2678

  • 255 Posts
  • 0 Reply Likes
navigator.app.exitApp() does not work on IOS, only Android. There is no way I know of to programmatically exit an IOS app. If someone does know...do tell :)
Photo of Joris Witteman

Joris Witteman

  • 1 Post
  • 0 Reply Likes
According to: http://stackoverflow.com/questions/35...

In ObjC:

exit(0)

or

[[NSThread mainThread] exit]
Photo of Rober Dote

Rober Dote

  • 1 Post
  • 1 Reply Like
i do it (:

-I was using a plugin screenshot (https://github.com/phonegap/phonegap-...)
-When this works well, modify the code (attached screenshots).

You modify Screenshot.m and Screenshot.h (add a simple method for close the app 'close(0);' )


create a javascript function


modify the Screenshot.js.


add the button to close you app


any question, contact me edades@gmail.com
greetings from chile =)
Photo of Alfredo Ortegón Sepúlveda

Alfredo Ortegón Sepúlveda

  • 1 Post
  • 1 Reply Like
if(navigator.app){

navigator.app.exitApp();
}else if(navigator.device){
navigator.device.exitApp();
}
Photo of Alberto Mendoza

Alberto Mendoza

  • 1 Post
  • 0 Reply Likes
I'll test this!
Photo of Vladimir Khazin

Vladimir Khazin

  • 1 Post
  • 0 Reply Likes
did not work for me. using cordova 3.6 on iPad 7.1.2
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
On iOS, you don't 'exit' an app. The user should simple press the home button, so he can fire up other apps. The running app is automatically canceled after a while of inactivity.
Photo of saravana kumar

saravana kumar

  • 1 Post
  • 0 Reply Likes
I have used navigator.app.exitApp()

Its Quit does not actually quit the app from memory and it is still running as a background process

How do we kill background process ?
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
You don't.
In iOS, the Operating System will do so after a while. In Android, the user can do so in the Settings-App section.
Photo of Daniel Guedes

Daniel Guedes

  • 1 Post
  • 0 Reply Likes
I don't know why this command doen not work on intel XDK.

:(
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
I don't know why you make that remark here, in a community about Phonegap Build, which you apparently don't use, anyway.
Photo of Benjamin Cassinat

Benjamin Cassinat

  • 1 Post
  • 0 Reply Likes
Maybe should tell him, instead of blame :)