• iOS应用通过委托对象AppDelegate类在应用周期的不同阶段会回调不同的方法,应用周期分为以下五种状态:

    • Not Running(非运行状态)。应用没有运行或被系统终止。  

    •   Inactive(前台非活动状态)。应用正在进入前台状态,但是还不能接受事件处理。

    •   Active(前台活动状态)。应用进入前台状态,能接受事件处理。

    • Background(后台状态)。应用进入后台后,依然能够执行代码。如果有可执行的代码,就会执行代码,

       如果没有可执行的代码或者将可执行的代码执行完毕,应用会马上进入挂起状态。
      
    •   Suspended(挂起状态)。处于挂起的应用进入一种“冷冻”状态,不能执行代码。如果系统内存不够,

      应用会被终止。 状态跃迁过程中应用回调的方法和本地通知

  •   应用状态改变的回调方法和本地通知
方法 本地通知 说明

application:didFinishLaun- chingWithOptions:

UIApplicationDidFinishLaunching- Notification

应用启动并进行初始化时会调用该方法并发 出通知。这个阶段会实例化根视图控制器

applicationDidBecomeActive:

UIApplicationDidBecomeActive- Notification

应用进入前台并处于活动状态时调用该方法 并发出通知。这个阶段可以恢复UI的状态(例 如游戏状态等)

applicationWillResignActive: 

UIApplicationWillResignActive- Notification

应用从活动状态进入到非活动状态时调用该 方法并发出通知。这个阶段可以保存UI的状 态(例如游戏状态等)

applicationDidEnterBackground:

UIApplicationDidEnterBackground- Notification

应用进入后台时调用该方法并发出通知。这 个阶段可以保存用户数据,释放一些资源(例 如释放数据库资源等)

 applicationWillEnterForeground:  

UIApplicationWillEnterForeground- Notification

应用进入到前台,但是还没有处于活动状态 时调用该方法并发出通知。这个阶段可以恢 复用户数据

applicationWillTerminate: UIApplicationWillTerminate- Notification 应用被终止时调用该方法并发出通知,但内 存清除时除外。这个阶段释放一些资源,也 可以保存用户数据 
  • 具体代码可查看AppDelegate
import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
return true
} func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
} func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
} func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
} func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
} func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
} }

iOS开发:应用生命周期的更多相关文章

  1. 【iOS开发】iOS对UIViewController生命周期和属性方法的解析

    iOS对UIViewController生命周期和属性方法的解析 一.引言 作为MVC设计模式中的C,Controller一直扮演着项目开发中最重要的角色,它是视图和数据的桥梁,通过它的管理,将数据有 ...

  2. (转)iOS应用程序生命周期(前后台切换,应用的各种状态)详解

    原文:http://blog.csdn.net/totogo2010/article/details/8048652 iOS应用程序生命周期(前后台切换,应用的各种状态)详解         分类:  ...

  3. iOS对UIViewController生命周期和属性方法的解析

    目录[-] iOS对UIViewController生命周期和属性方法的解析 一.引言 二.UIViewController的生命周期 三.从storyBoard加载UIViewController实 ...

  4. 转:iOS应用程序生命周期(前后台切换,应用的各种状态)详解

    iOS应用程序生命周期(前后台切换,应用的各种状态)详解 分类: iOS开发进阶2012-10-08 15:35 42691人阅读 评论(30) 收藏 举报 iosapplication任务anima ...

  5. android开发之生命周期

    android开发之生命周期 一:Activity的生命周期: 这几天了了解了安卓Activity的生命周期,对于生命周期有了大概的理解: 一个Activity的生命周期也就是Activity从生成到 ...

  6. Android开发——Activity生命周期

    Android开发--Activity生命周期 Activity作为四大组件之首,也是使用最频繁的一种组件.本文将主要讲解Activity生命周期,包括正常情况下的Activity生命周期和异常情况下 ...

  7. 浅尝Spring注解开发_Bean生命周期及执行过程

    Spring注解开发 浅尝Spring注解开发,基于Spring 4.3.12 包含Bean生命周期.自定义初始化方法.Debug BeanPostProcessor执行过程及在Spring底层中的应 ...

  8. iOS - ViewController的生命周期

    iOS SDK中提供很多原生的ViewController,大大提高了我们的开发效率:那么下面我们就根据开发中我们常用的ViewController谈一谈它的生命周期: (一)按照结构和用法可以对iO ...

  9. iOS控制器的生命周期分析和使用

    转自http://blog.csdn.net/qijianli/article/details/7826979 iOS的SDK中提供很多原生ViewController,大大提高了我们的开发效率,下面 ...

  10. [转]iOS应用程序生命周期(前后台切换,应用的各种状态)详解

    转载地址:http://blog.csdn.net/totogo2010/article/details/8048652 iOS的应用程序的生命周期,还有程序是运行在前台还是后台,应用程序各个状态的变 ...

随机推荐

  1. asp.net中的mysql传参数MySqlParameter

    注意在asp.net中传参 string sql="select name,id from user where id=@id"; //@idm不需要引号 MySqlParamet ...

  2. 动态更新Toolbar Menu以及Menu中同时显示文字和图标

    动态更新Toolbar Menu以及Menu中同时显示文字和图标 我们经常会有这样的需求,在切换Fragment或者点击某个按钮后动态更新Toolbar上Menu项.但是onCreateOptions ...

  3. tomcat 运行异常Cannot create PoolableConnectionFactory (到主机 的 TCP/IP 联接失败)(用户sa登录失败)

    这是在java web中启动tomcat遇到的问题,因为这个问题,整整折腾了两天的时间,找了很都解决方案,但终究还是不能正常.现在整理下这个问题的解决方案: 首先,出这个问题之前,请检查一下的问题,这 ...

  4. Capsule:开源的 JVM 应用部署工具

    [编者按]本文作者 Ron Pressler 是 Parallel Universe 公司的创始人,拥有着丰富的高性能开发经验.通过这篇文章,Ron 向大家详细介绍了全新的开源 JVM 部署工具--C ...

  5. StringBuffer用法

    public class StringBufferTest { public static void main(String[] args) { StringBuffer sb=new StringB ...

  6. POJ2104 K-th number 函数式线段树

    很久没打代码了,不知道为什么,昨天考岭南文化之前突然开始思考起这个问题来,这个问题据说有很多种方法,划分树什么的,不过对于我现在这种水平还是用熟悉的线段树做比较好.这到题今年8月份的时候曾经做过,那个 ...

  7. Matlab安装

    第一步:下载MATLAB 7.0,下载自己百度下就好. 三个ios文件 第二步:把每个IOS文件直接右键解压就好. 第三步:打开第一个解压文件夹.双击.exe文件 第四步:next之后把序列号黏贴上去 ...

  8. sql 判断两个时间段是否有交集

    本文转自CSDN 链接地址:http://blog.csdn.net/dasihg/article/details/8450195 时间段:starttime_1到endtime_1,starttim ...

  9. sql中临时表的创建和使用【本文转自多人博客】

    本模块原网址:http://www.cnblogs.com/jeffwongishandsome/archive/2009/08/05/1526466.html 原作者:Jeff Wong 1.创建方 ...

  10. hdu 1452 Happy 2004

    因子和: 的因子是1,2,3,6; 6的因子和是 s(6)=1+2+3+6=12; 的因子是1,2,4,5,10,20; 20的因子和是 s(20)=1+2+4+5+10+20=42; 的因子是1,2 ...