views:

91

answers:

2

Is there any possiblity for reacting to the event that a user kills your app via the multitasking bar if it has moved to the background? According to my observations, applicationWillTerminate: does NOT get called.

It seems to me that there is no possiblity for cleaning up before quitting in this case.

A: 

It should get called. Are you depending on NSLog to tell you when it does get called? When an app goes into the inactive state by pressing the home button then any further NSLogs are not printed to the console. You could try showing a small UIAlertView to see of it does get called instead.

sciritai
Yes, i've been using `NSLog`. I don't think I can show an `UIAlertView` when terminating while in background.
tob
This is wrong. When your app is in the background and it's killed you get no warning.
kubi
+1  A: 

If an app needs to do any cleanup or shutdown, under iOS 4.x it should do this when the app's suspend delegate gets called, just before the app gets sent to the background, since there is no guarantee that the app will ever get any run time again, either due to user action or memory cleanup.

If the app's Deployment Target also includes iPhone OS 3.x, then it should also do cleanup in its terminate delegate, as that will get called instead of suspend.

hotpaw2
But what if I've started some kind of background service such as listening to location updates while in background? How can I clean up these resources?
tob