Application Activate and Deactivate

When waking up i.e. relaunching an app (either through springboard, app switching or URL)applicationWillEnterForeground: is called. It is only executed once when the app becomes ready for use, after being put into the background, while applicationDidBecomeActive: may be called multiple times after launch. This makes applicationWillEnterForeground: ideal for setup that needs to occur just once after relaunch.

applicationWillEnterForeground: is called:

  • when app is relaunched
  • before applicationDidBecomeActive:

applicationDidBecomeActive: is called:

  • when app is first launched after application:didFinishLaunchingWithOptions:
  • after applicationWillEnterForeground: if there's no URL to handle.
  • after application:handleOpenURL: is called.
  • after applicationWillResignActive: if user ignores interruption like a phone call or SMS.

applicationWillResignActive: is called:

  • when there is an interruption like a phone call.
    • if user takes call applicationDidEnterBackground: is called.
    • if user ignores call applicationDidBecomeActive: is called.
  • when the home button is pressed or user switches apps.
  • docs say you should
    • pause ongoing tasks
    • disable timers
    • pause a game
    • reduce OpenGL frame rates

applicationDidEnterBackground: is called:

  • after applicationWillResignActive:
  • docs say you should:
    • release shared resources
    • save user data
    • invalidate timers
    • save app state so you can restore it if app is terminated.
    • disable UI updates
  • you have 5 seconds to do what you need to and return the method
    • if you dont return within ~5 seconds the app is terminated.
    • you can ask for more time with beginBackgroundTaskWithExpirationHandler:

1.程序启动时一致

iOS4.3iOS5.0

didFinishLaunchingWithOptions->UIApplicationStateInactive

applicationDidBecomeActive->UIApplicationStateActive

 

2.锁屏键不同

Lock

iOS4.3

applicationWillResignActive->UIApplicationStateActive

 

iOS5.0

applicationWillResignActive->UIApplicationStateActive

applicationDidEnterBackground->UIApplicationStateInactive

 

Unlock:

iOS4.3

applicationDidBecomeActive->UIApplicationStateActive

 

iOS5.0

applicationWillEnterForeground->UIApplicationStateInactive

applicationDidBecomeActive->UIApplicationStateActive

 

3.单击Home一致

入:

iOS4.3iOS5.0

applicationWillResignActive->UIApplicationStateActive

applicationDidEnterBackground->UIApplicationStateBackground

 

返回:

iOS4.3iOS5.0

applicationWillEnterForeground->UIApplicationStateBackground

applicationDidBecomeActive->UIApplicationStateActive

 

4.双击Home一致

进入:

iOS4.3iOS5.0

applicationWillResignActive->UIApplicationStateActive

 

返回:

iOS4.3iOS5.0

applicationDidBecomeActive->UIApplicationStateActive

 

 

5.终结程序时一致

iOS4.3iOS5.0

applicationWillResignActive->UIApplicationStateActive

applicationDidEnterBackground->UIApplicationStateBackground

你可能感兴趣的:(application)