5 status in iOS apps

Source: Internet
Author: User

1. Not Running (non-running state). The app is not running or terminated by the system. 2. Inactive (non-active reception). The app is entering the foreground state, but it cannot accept event processing. 3.Active (foreground activity status). The application enters the foreground state and can accept event processing. 4.Background (background state). The app is still able to execute code after it enters the background. If there is executable code, the code executes, and if there is no executable code or the executable code is executed, the application will go into the pending state immediately. 5. Suspended (hang State). A pending application enters a "frozen" state and cannot execute code. If the system does not have enough memory, the application is terminated. During the app state transitions, the iOS system will callback some of the methods in Appdelegate and send some notifications. In fact, there are many methods and notifications used in the life cycle of the application, methods for applying callbacks during state transitions, and local notifications
application:didFinishLaunchingWithOptions:UIApplicationDidFinishLaunchingNotification

The method is invoked and notified when the app is started and initialized. This stage instantiates the root view controller

applicationDidBecomeActive:UIApplicationDidBecomeActiveNotification

The method is called and notified when the app enters the foreground and is active. This stage can restore the state of the UI (e.g. game state, etc.)

applicationWillResignActive:    UIApplicationWillResignActiveNotification   

The method is called when the app enters the inactive state from the active state and is notified. This stage can save the state of the UI (e.g. game state, etc.)

applicationDidEnterBackground:UIApplicationDidEnterBackgroundNotification

The method is called and notified when the app enters the background. This stage can save the user data, release some resources (such as freeing up the database resources, etc.)

applicationWillEnterForeground:UIApplicationWillEnterForegroundNotification

The application enters the foreground, but is not yet active when the method is called and a notification is issued. This phase can restore user data

applicationWillTerminate:UIApplicationWillTerminateNotification

The method is called when the app is terminated, except when the memory is cleared. This phase frees up some resources and can also save user data

To make it easier to observe the running state of the application, we add some log output for the method in APPDELEGATE.M, with the following code:
 @implementation appdelegate - (BOOL) Application: (uiapplication*) Application Didfinishlaunchingwithoptions: (nsdictionary*) launchoptions{NSLog(@"%@", @"Application:didfinishlaunchingwithoptions:"); ......return YES;} - (void) Applicationwillresignactive: (uiapplication*) application{NSLog(@"%@", @"applicationwillresignactive:");} - (void) Applicationdidenterbackground: (uiapplication*) application{NSLog(@"%@", @"Applicationdidenterbackground:");} - (void) Applicationwillenterforeground: (uiapplication*) application{NSLog(@"%@", @"Applicationwillenterforeground:");} - (void) Applicationdidbecomeactive: (uiapplication*) application{NSLog(@"%@", @"applicationdidbecomeactive:");} - (void) Applicationwillterminate: (uiapplication*) application{NSLog(@"%@", @"Applicationwillterminate:");}@end

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

5 status in iOS apps

Related Article

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.