为了处理好应用程序的挂起、暂停等情况下的数据保存,或对应添加所需处理,我们必须了解ios生命周期。

但是不要去背去记,做个实验就好。


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    NSLog(@"程序开始");
    return YES;
}
                            
- (void)applicationWillResignActive:(UIApplication *)application
{
    // 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.
    NSLog(@"程序暂停");
} - (void)applicationDidEnterBackground:(UIApplication *)application
{
    // 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.
    NSLog(@"程序进入后台");
} - (void)applicationWillEnterForeground:(UIApplication *)application
{
    // 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.
    NSLog(@"程序进入前台");
} - (void)applicationDidBecomeActive:(UIApplication *)application
{
    // 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.
    NSLog(@"程序再次激活");
} - (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    NSLog(@"程序意外终止");
}

实验结果:

1.首次启动应用程序:

2012-06-26 11:06:39.313 WQTest[485:17903] 程序开始

2012-06-26 11:06:39.320 WQTest[485:17903] 程序再次激活

2.摁HOME键退出:

2012-06-26 11:08:08.687 WQTest[485:17903] 程序暂停

2012-06-26 11:08:08.690 WQTest[485:17903] 程序进入后台

 

3.再次进入程序:

2012-06-26 11:09:11.047 WQTest[485:17903] 程序进入前台

2012-06-26 11:09:11.049 WQTest[485:17903] 程序再次激活

iOS开发——生命周期的更多相关文章

  1. 图解ios程序生命周期

    图解ios程序生命周期 应用程序启动后状态有Active.Inactive.Background.Suspended.Not running这5种状态,几种状态的转换见下图: 在AppDelegate ...

  2. (转)深入浅出 iOS 之生命周期

    原文:http://www.cocoachina.com/applenews/devnews/2011/0817/3129.html 深入浅出 iOS 之生命周期 发布于:2011-08-17 10: ...

  3. 【PMP】项目生命周期和开发生命周期

    一.定义 项目生命周期:指项目从启动到完成所经历的一系列阶段. 开发生命周期:项目生命周期内通常有一个或多个阶段与产品.服务或成果的开发相关,这些阶段称为开发生命周期. 二.生命周期 预测型生命周期( ...

  4. 【应用安全】S-SDLC安全开发生命周期

    0x01 S-SDLC简介 OWASP Secure Software Development Lifecycle Project(S-SDLC)是OWASP组织首个由OWASP中国团队独立发布并主导 ...

  5. 【应用安全】微软的安全开发生命周期(SDL)

    0x01 SDL介绍 安全开发生命周期(SDL)即Security Development Lifecycle,是一个帮助开发人员构建更安全的软件和解决安全合规要求的同时降低开发成本的软件开发过程. ...

  6. 【转】深入浅出 iOS 之生命周期

    [iOS]深入浅出 iOS 之生命周期 深入浅出 iOS 之生命周期  http://blog.csdn.net/kesalin/article/details/6691766 罗朝辉(http:// ...

  7. 【转】VS 安全开发生命周期(SDL)检查

    前面在学习使用google的protobuf时在VS2012中一直无法编译编译通过,经过查找一些资料原来发现,并不是protobuf的问题,而是自己在使用VS2012时,没有完全了解VS2012的强大 ...

  8. 软件开发生命周期(SDLC)

    一.简介 软件开发生命周期又叫做 SDLC(Software Development Life Cycle),它是集合了计划.开发.测试和部署过程的集合.如下图所示 : 二.五个阶段 1.分析阶段: ...

  9. 【Xamarin 开发 IOS --IOS ViewController生命周期】

    ViewController ViewController是IOS开发中MVC模式中的C,ViewController是view的controller,ViewController的职责主要包括管理内 ...

随机推荐

  1. Sql添加测试数据

    --建测试表 CREATE TABLE T_UserInfo ( Userid varchar(20),  UserName varchar(20), RegTime datetime, Tel va ...

  2. Android-->Realm(数据库ORM)使用体验,lambda表达式

    Realm,为移动设备而生.替代 SQLite 和 Core Data. 非常庆幸,官方帮助文档有中文: https://realm.io/cn/docs/java/latest/ 尽管眼下最新的版本 ...

  3. Objective-C之成魔之路【5-选择结构】

    郝萌主倾心贡献.尊重作者的劳动成果,请勿转载. 假设文章对您有所帮助,欢迎给作者捐赠,支持郝萌主.捐赠数额任意,重在心意^_^ 我要捐赠: 点击捐赠 Cocos2d-X源代码下载:点我传送 Objec ...

  4. python字符串操作,以及对应的C#实现

    --IndexOf-- python: inx = str.find("aa") c#: var inx = str.IndexOf("aa"); --Last ...

  5. python学习之os.walk()

    os.walk(top,topdown = True,onerror = None,followlinks = False) 参数 top -- 根目录下的每一个文件夹(包含它自己), 产生3-元组 ...

  6. 关于 web中 使用 java.net.URLEncoder.encode 要编码两次呢 , js的encodeURIComponent 同理

    因为在jsp中对中文进行了编码的时候用的是UTF-8的编码方式,而在servlet中调用request.getParameter();方法的时候使用服务器指定的原始编码格式(ISO-8859-1)自动 ...

  7. hive执行更新和删除操作

    Hive从0.14版本开始支持事务和行级更新,但缺省是不支持的,需要一些附加的配置.要想支持行级insert.update.delete,需要配置Hive支持事务. 一.Hive具有ACID语义事务的 ...

  8. linux grub 使用

    linux kernel 格式之 vmlinux.zImage.bzImage.vmlinuz.uImage vmlinux     是编译出来的未经压缩的原始内核文件,是linux接受的可执行文件格 ...

  9. webapck卸载以及更换版本

    有时候我们需要安装webpack的指定版本,但是又安装了webpack的其他版本,就需要先卸载webpack 1.先执行 npm uninstall webpack -g 2.找到webpack的文件 ...

  10. oracle+SQL优化实例

    1.     减少I/O操作: SELECT COUNT(CASE WHEN empno>20 THEN 1 END) c1,COUNT(CASE WHEN empno<20 THEN 1 ...