views:

75

answers:

1

I have made a small test app with a button and a UISlider. Touching the button changes its label text. I have added IBOutlet properties for both controls. I'm releasing all properties in viewDidUnload and also set them to nil in dealloc.

The interesting thing is now: I touch the button. Its tag is changed from "0" to "1" and, its text is updated: tag == 1 -> "B", tag == 0 -> "A". So the text says "B" now. Then I close the App (iPhones home button) and restart it. Still the button says "B"! How is that possible? Is the App not terminated?

Running on iOS4.1 here on an iPhone 4.

René

+2  A: 

You're right. The app is not terminated. In iOS 4, apps are suspended when the home button is pressed. When you "relaunch" the app, it is simply moved to the foreground. This is why your application state isn't changing. Note: Once suspended, apps may be terminated by the OS without notification, so make sure to do all your saving before the app gets suspended, e.g., in applicationDidEnterBackground:.

James Huddleston
That's scary stuff. :-)
Krumelur
Can I force the application to "die"? I mean, can I call anything in "applicationDidEnterBackground" to really end the app?
Krumelur
The appropriate way to prevent your app from being suspended is to opt out. In your app's Info.plist file, set the value of UIApplicationExitsOnSuspend to YES. If you do this, when the user taps the home button the applicationWillTerminate: method of your app delegate will be called and then your application will terminate.
James Huddleston