views:

1284

answers:

4

Before iOS4.0 clicking the home button on iPhone exits the application, and Apple had in their guide that programmatically exiting the application was not accepted.

now everything changed in iOS4.0, clicking the home button puts your app in a suspended mode (multitasking).. and I think there should be a clear way for the user to exit the app, like an exit button.

is it now OK with apple? and how can it be done?

+1  A: 

No still shouldn't do this.

You have handlers for the different stages, so this is how you should do it. There's no point in exiting manually. If you restart the app, ideally it would start where you left off, so this is either by resuming or by starting and loading the old state.

No reason for exit.

Eiko
I can't see why it is not acceptable to put an exit button for the user. every time I double click the home button I have dozen of suspended apps, and they keep growing, which really annoys me, and I think all iPhone users will feel the same.
Tamer
You're thinking of it the wrong way. Those apps aren't your suspended apps. Those apps are just the apps that the user's used recently.The fact that some of them are in different stages of freeze is irrelevant on the iPhone.
Steven Fisher
@tewha, these are active apps (from user point of view), frozen or suspended, but not user just last used apps. I still think there should be a way to close the app, rather than stack them in the task list.
Tamer
What is the difference to the user? Why should he want to exit, if he doesn't notice a difference? It's not about ressources, as the apps will be killed if ressources get low.
Eiko
mmmmmmmmm... this way the task bar (switcher) is useless, imagine every app the user opens stays there, and if he wants to switch to another app he has to scroll among 30 apps or so. Anyway, I look all around and I think it is how Apple wants it :) .
Tamer
Even though this No answer was accepted, there is a way to make your app exit instead of suspending. See [Joost's answer](http://stackoverflow.com/questions/3097244/exit-application-in-ios-4-0/3098252#3098252) below.
progrmr
@progrmr: Sure, you can disable going to background, but you cannot give the user the choice (doing this in some of our apps). I thought question was how to programmatically *end* the program (and this is still dicouraged). How is preventing from going to suspend mode within the plist a "clear way for the user to exit the app, like an exit button"?
Eiko
I interpreted the question as how to get the pre-4.0 home button behavior, with his idea of an answer being an exit button. I agree with you that an exit button is not the solution, but there is a way to get the pre-4.0 behavior so no need for an exit button (in <4.0 the Home button was the exit button).
progrmr
+7  A: 

You can set the Info.plist key UIApplicationExitsOnSuspend to make sure the app is completely terminated.

Joost Schuur
+1 Yes you can opt out of background execution and have your app terminate instead of suspending, [read the docs here](http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/CoreApplication/CoreApplication.html#//apple_ref/doc/uid/TP40007072-CH3-SW24)
progrmr
A: 

Tamer is absolutely right. The list keeps growing and it does get annoying and pointless to have the list.

Zach Liebman
FYI, this should be a comment, not an answer.
bmoeskau
FYI, you need 50 reputation before you can comment!
ohhorob
A: 

I had a real problem with this. There is a big point in exiting manually or prgramatically.

With previous iPhone OS, my app was writing out its state (first use or second time onwards, etc.) in a plist when it terminated. When the user came back, it wanted to show different things by reading the plist. Also, it wanted to show the first screen every time when the user came back after exiting.

With app becoming suspended in the background with iPhone OS4, the app comes back where it left off (i.e. showing the same screen wherever the user was on) and never changes the state of it, because applicationWillTerminate is now never called.

Becasue this is the behaviour desired most of the time (to be able to continue when you step out of the app temporary), there has to be a way to be able to choose, i.e. suspend it or quit.

Since setting the UIApplicationExitsOnSuspend=YES gives only one way (i.e. it always terminates when the HOME is pressed), this is not a solution I am looking for.

I want the app to know once the whole chain of steps are completed, opposed to just the sequence was suspended, and to quit itself at the right time.

To do this, I have to be able to terminate the app and write out the state once the use completed the entire sequence. Other times, I just want the app to be suspended.

If you tap the HOME button twice you can see the suspended apps. I can delete (quit) my app by touching it longer and touch the (-) symbol that comes up, but this is not so intuitive for the users and too many steps.

Another option is to have a Quit button as one of the Nav Tabs in my app, but that is ugly. For now, my only option seems to be opting to set the UIApplicationExitsOnSuspend=YES.

Yoichi