Search code examples
ios4lifecycle

iOS app lifecycle 4/3GS/iPad vs 2G/3G


I've read the Apple's documentation about application lifecycle and made some tests to figure out what is the applications life cycle on different devices. (All running iOS 4.x except the 2G)

I've tested "multitasking" capable devices vs some that do not support this feature :

iPhone 2G/3G app lifecycle :

(START)
- didFinishLunchingWithOptions
- applicationDidBecomeActive

(HOME PRESSED)
- applicationDidEnterBackground
- appWillTerminate

iPad / iPhone 4 app lifecycle:

(START)
- didFinishLunchingWithOptions
- applicationDidBecomeActive

(HOME PRESSED)
- appWillResignActive
- appDidEnterBackGround

(RESART app in the "Taskbar")
- appWillEnterForeGround
- appDidBecomeActive

I've tried to kill the App from the "taskbar" but the debugger received a SIGKILL ! What happens when you kill and app in that way ?

When is appWillTerminate called on the "multitasking" capable device ? Are my results correct ?

EDIT:

Quote from apple's doc about appWillTerminate :

For applications that support background execution, this method is generally not called when the user quits the application because the application simply moves to the background in that case. However, this method may be called in situations where the application is running in the background (not suspended) and the system needs to terminate it for some reason.

What do they mean by "generally not called". " the system needs to terminate it.." means that the method appWillTerminate will be invoked ?


Solution

  • I think you're right. When you kill an app from the taskbar (or when your device is running low on memory and the OS kills the app for you), it just sends a SIGKIL signal. As you note, it never calls any of the callbacks.

    According to the documentation:

    For applications that support background execution, this method is generally not called when the user quits the application because the application simply moves to the background in that case. However, this method may be called in situations where the application is running in the background (not suspended) and the system needs to terminate it for some reason.

    So, iOS can call the applicationWillTerminate: method but probably won't. (I've never seen it.)

    If you want to save any state before your app is killed, you need to do it as it goes into the background.