Can you close a Phonegap application?

23,746 views
Skip to first unread message

Nicole B. Torcolini gmail

unread,
Jul 30, 2011, 11:15:43 PM7/30/11
to Phonegap
Is there a way to close a Phonegap application? I tried window.close(), but nothing happens.

eyal

unread,
Jul 31, 2011, 12:41:18 AM7/31/11
to phon...@googlegroups.com
on android 

device.exitApp();

Viras

unread,
Jul 31, 2011, 3:23:30 PM7/31/11
to phon...@googlegroups.com
Just as a side note: some device vendors may forbid to exit an app
explicitly (like Apple does)

Am 31.07.2011 05:15, schrieb Nicole B. Torcolini gmail:
> Is there a way to close a Phonegap application? I tried window.close(),
> but nothing happens.
>

> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>
> For more info on PhoneGap or to download the code go to www.phonegap.com

Nicky

unread,
Jul 31, 2011, 3:27:53 PM7/31/11
to phonegap
Is there a way to do it on the iPhone? I keep forgetting to say that I
am developing an iPhone application.

Phil

unread,
Jul 31, 2011, 3:45:30 PM7/31/11
to phonegap
Why would you need to do that? That's not how iOS apps work.

Thanks.

-Phil

BG1FPX

unread,
Jul 31, 2011, 1:34:25 AM7/31/11
to phonegap
or

navigator.device.exitApp();

Viras

unread,
Aug 1, 2011, 1:53:52 AM8/1/11
to phon...@googlegroups.com
Don't do that because your App will be rejected by Apple.

Application closing is only allowed through the "Home" button of the iOS
device and should never be called by your app explicitly.

Devgeeks

unread,
Aug 1, 2011, 2:43:50 AM8/1/11
to phon...@googlegroups.com
You can do that via your app's Info.plist, however... 


NOTE: The answer also states: "In practice, Apple strongly recommends you not do this unless you have a very good reason for this behavior."

Shazron Abdullah

unread,
Aug 1, 2011, 8:06:00 AM8/1/11
to phon...@googlegroups.com
A difference - that plist setting is for multi-tasking on iOS 4 (ExitsOnSuspend).

Apple relies on "guidelines" and (usually!) they follow their HIG (Human Interface Guidelines), and quote:
------------
"Never quit an iOS application programmatically because people tend to interpret this as a crash. However,
if external circumstances prevent your application from functioning as intended, you need to tell your users
about the situation and explain what they can do about it. Depending on how severe the application
malfunction is, you have two choices.

Display an attractive screen that describes the problem and suggests a correction. A screen provides
feedback that reassures users that there’s nothing wrong with your application. It puts users in control, letting
them decide whether they want to take corrective action and continue using your application or press the
Home button and open a different application.

If only some of your application's features are not working, display either a screen or an alert when
people activate the feature. Display the alert only when people try to access the feature that isn’t functioning."
------------

Apple HIG:
http://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/MobileHIG.pdf
(section "Don’t Quit Programmatically", page 65)

Probability is not in your favour however unless you follow the above. I would say "never" is pretty absolute, but then...

Carlos Mondragón

unread,
May 14, 2012, 4:08:30 PM5/14/12
to phon...@googlegroups.com
What about cases when the app requires an internet connection and not having it makes it impossible to use it? Apps like Draw Something show you a notification box and then close the app. 

--

Kerri Shotts

unread,
Jul 18, 2012, 1:37:26 AM7/18/12
to phon...@googlegroups.com, phon...@googlegroups.com
Don't use this on an iOS device -- 1) Apple will not accept your app into the store, and 2) this is not the expected behavior for iOS apps. An app quitting on its own will present as a crash.

If an app needs to be restarted in order for some setting to take effect, the app should indicate this to the user and allow the /user/ to force-quit the app on their own.

If the app needs to exit, again, allow the user to do it themselves. Technically, the app will eventually be terminated anyway (due to being flushed out of memory after using other apps), or the user can terminate the app. IMNSHO, there is never, ever a legitimate reason for having an "exit" button in an iOS app. (Android is different, and so I understand.)

That said, if it is working on an iPhone it should work just fine on an iPad. That said, I'd double check your iPhone and make sure you aren't actually generating a crash instead...? And by "not working" on the iPad, exactly /how/ is it not working? Does the app just go on its merry way? Does it exit to the home screen, but then actually not terminate? Also, we need more information on the devices and iOS versions you are using. (e.g., an ipad 3 running ios 6 may react very differently than an iphone 3gs running ios 4. In fact, /probably/ will.)

Side note -- if this is a matter of needing to reload content after a period of time or after being resumed, you can do that without having to exit the app. Just listen for the pause/resume events, save the clock on pause, look at it again on resume, and if longer than a given period of time, refresh your app's contents. Or, if you /must/, refresh the entire page/reload your index page (yes, that works; essentially you are restarting your app inside PhoneGap).



______________________________
Kerri Shotts
photoKandy Studios LLC

📱 Phone: +1 (312) 380-1035
🌐 Web: http://photokandy.com 

Twitter: @photokandy

 
On Jul 17, 2012, at 21:09, Daniel Yeung <daniel....@gmail.com> wrote:

Hi,

    I use the following code fragment, it can work on both Android phone and iPhone, but it don't work on iPad.
    Does anybody know an alternative for iPad?

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

--
-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to

For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
 
To compile in the cloud, check out build.phonegap.com
 
 

Captain Obvious

unread,
Sep 17, 2012, 9:01:59 PM9/17/12
to phon...@googlegroups.com
if (confirm("Exit App?")) navigator.app.exitApp();

Kerri Shotts

unread,
Jan 25, 2013, 2:48:58 PM1/25/13
to phon...@googlegroups.com, nbto...@gmail.com
And does that make it through the Apple App Store? Closing an app programmatically is specifically against the HIG (last I checked).

I know I've seen apps (native, even) have settings that only worked after a restart, but none of them do that restart for you -- they just tell you how to force-quit the app. If native apps don't do it, I'd be very surprised if Apple would let a PG app through that did it. (But then again, every reviewer applies the HIG differently, so maybe they do let it through more often than I realize.)

___________________________________
Kerri Shotts
photoKandy Studios, LLC


Social Media:
          Twitter: @photokandy, http://twitter.com/photokandy
          Tumblr: http://photokandy.tumblr.com/
          Github: https://github.com/kerrishotts
                        https://github.com/organizations/photokandyStudios
          CoderWall: https://coderwall.com/kerrishotts

Apps on the Apple Store:

On Friday, January 25, 2013 at 12:43 PM, Roberto Dote wrote:

I can do it for iOS (iPad2). with the help of a plugin for PhoneGap.
published as modified capture.


I hope it helps.

greetings from chile

El sábado, 30 de julio de 2011 23:15:43 UTC-4, Nicole B. Torcolini gmail escribió:
Is there a way to close a Phonegap application? I tried window.close(), but nothing happens.

--

Deepak Bandela

unread,
Nov 8, 2013, 2:59:20 PM11/8/13
to phon...@googlegroups.com, nbto...@gmail.com
Very simple. if iOS doesn't allow closing app automatically. Just make a crash on click of exit.

iOS doesn't even show it is a crash. hence problem solved.

Kerri Shotts

unread,
Nov 9, 2013, 3:38:31 PM11/9/13
to phon...@googlegroups.com, nbto...@gmail.com
Yeah, no.

A crashing app doesn't get any of the nice exit features, and users know to associate this with a crashed app -- which is not a good impression to leave with your users.

Apple also indicates that apps should not quit themselves in this manner (as there is a way to do this natively, but it still /looks/ like a crash). Doing so is a great way to get your app rejected.

Also keep in mind that iDevices store crash logs, and any users let those go on to Apple. I really wouldn't want my app explicitly crashing and then having those logs end up at Apple. 

So no -- don't quit your app by crashing it. The HIG pretty clearly indicates you should never have need to do this or ask the user to do it. Some apps get away with asking users to restart, but this is frowned upon as well. Instead, make every effort to interact with the device events (resume, pause, etc.), clean up nicely upon termination, and restore to the last known state as completely as possible.
Reply all
Reply to author
Forward
0 new messages