More Comments on iOS 4 Multitasking

Some More Comments on iOS 4 Multitasking.

Expiration Handlers

If a process is running in background, having issued UIApplication's beginBackgroundTask before, then the process expiration handler's code following the (last) issuing of endBackgroundTask is not executed. In other words: iOS 4 does not wait until your expiration handler block is finishes. It waits for the last endBackgroundTask and terminates the app (quite ungracefully).

View Controllers

If your app enters background the active view controller does not receive a viewWillDisappear. Neither will it receive a viewWillAppear if the app enters foreground.

Application Lifecycle

On iOS 4.0 the message applicationWillTerminate is rarely send. I made some tests and found the follwoing:
  • An app will not receice applicationWillTerminate if it is in background and user selects force quit (pressing the minus sign in the list of recent apps).
  • An app will not receive applicationWillTerminate if is is in background and the user selects to shut down the device while your app is running.
  • An app will not receice applicationWillTerminate if it is in background and system shuts down due to low battery.
  • An app will receive applicationWillTerminate if it is in foreground and sytem shuts down due to low battery.
  • An app will receive applicationWillTerminate if it is in foreground and the user selects to shut down the device while your app is running.
If you like to save the state of your app you have to do so in applicationWillTerminate (for OS 2.x, 3.x and 4.x) and (!) in applicationDidEnterBackground (for OS 4.0).