Diagram The iOS program life cycle

Source: Internet
Author: User
Tags terminates

Diagram The iOS program life cycle

After the application starts, there are 5 states of active, Inactive, Background, Suspended, not running , and several state transitions are shown:

When the app state changes, the callback function is implemented in Appdelegate, and the system executes the corresponding callback when the app status changes:

-(BOOL) Application: (UIApplication *) application willfinishlaunchingwithoptions: (nsdictionary *) launchOptions
Tells the agent that the process has started but has not yet entered a state save
-(BOOL) Application: (UIApplication *) Applicationdidfinishlaunchingwithoptions: (Nsdictionary *) launchOptions
Tells the agent to start the basic Completion program ready to start running
-(void) Applicationwillresignactive: (uiapplication *) Application
When an application is going into an inactive state, during which time the application does not receive messages or events, such as coming to the phone
-(void) Applicationdidbecomeactive: (uiapplication *) Application
When the application executes in the active state, this is exactly the opposite of the method above.
-(void) Applicationdidenterbackground: (uiapplication *) Application
Called when the program is pushed to the background. So to set the background to continue running, you can set it in this function
-(void) Applicationwillenterforeground: (uiapplication *) Application
Called when the program is going back to the foreground from the background, which is exactly the opposite of the method above.
-(void) Applicationwillterminate: (uiapplication *) Application
When the program is about to exit is called, it is usually used to save the data and some cleanup work before exiting. This needs to set the key value of the uiapplicationexitsonsuspend.
-(void) applicationdidfinishlaunching: (uiapplication*) Application
Executes when the program is loaded

1. When the program starts:

, when the app starts, it first switches from the not running state to the inactive state, at which point the application:didfinishlaunchingwithoptions is called: method The inactive state is then switched to the active state, at which point the Applicationdidbecomeactive: method is called.

2. Program into the background

  After entering the background, if the app is not required to run in the background (there are several scenarios that can be run in the background on the first picture), then the state of the program (such as when suspend when not running) is completely system controlled.

When you switch to another app, the state active switches to inactive, which calls Applicationwillresignactive: method, and then switches from inactive state to running state, This calls the Applicationdidenterbackground: method.

3. Program back to foreground

When switching back to the original app, the running state switches to the inactive state, at which point the Applicationwillenterforeground: method is called and then switched from the inactive state to the active state. Call Applicationdidbecomeactive: Method.

4. Interrupts

When the app is interrupted (to call or pull out the toolbar above), the active state switches to the inactive state, at which point the Applicationwillresignactive: method is called.

5. Lock Screen

When the phone locks the screen, the state active switches to inactive, which calls Applicationwillresignactive:; and then switch from inactive state to running state, This calls the Applicationdidenterbackground: method.

6. Program Termination: The program will be terminated as long as it is in the background or pending state if one of the following conditions is met: (1) iOS4.0 the previous system, the app was developed based on the iOS4.0 system, and the device does not support multi-tasking. (2) in the Info.plist file, the program contains the Uiapplicationexitsonsuspend key.  (3) When the system resources are insufficient, the system dispatch terminates the app. If the app terminates, the system calls the app's proxy method Applicationwillterminate, which allows you to do some cleanup work. You can save some data or app status. This method also has a 5-second limit.  After a timeout, the method returns the program from memory cleanup. Note: Users can close the application manually. Reference

1. An explanation of the iOS app lifecycle (pre-background switch, application status)

2. deep analysis of the life cycle of iOS apps

3. How the new background multitasking (multitasking) mechanism for IOS 7 works

  

Diagram The iOS program life cycle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.