为了处理好应用程序的挂起、暂停等情况下的数据保存,或对应添加所需处理,我们必须了解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. php serialize序列化对象或者数组

    serialize序列化对象或者数组 $str=serialize(array('a'=>1,'b'=>2)); echo $str; 输入出a:2:{s:1:"a"; ...

  2. php面象对象魔术方法的使用

    class Moshu{ public $number; public function __construct($str)//构造方法,new实例时,自动调用 { //require('/confi ...

  3. mysql中实现分类汇总功能

    1.创建测试表: CREATE TABLE test_ROLLUP_1 ( StateCode ), DepCode ), SendMoney INT ); 2.插入测试语句: INSERT INTO ...

  4. 智能指针tr1::shared_ptr、boost::shared_ptr使用

    对于tr1::shared_ptr在安装vs同一时候会自带安装,可是版本号较低的不存在.而boost作为tr1的实现品,包括 "Algorithms Broken Compiler Work ...

  5. PMON

    PMON是一个兼有BIOS和boot loader部分功能的开放源码软件,多用于嵌入式系统. 与BIOS相比功能不足,与常见的bootloader 相比,功能要丰富的多.基于龙芯的系统采用 pmon ...

  6. 基于AXI VDMA的图像采集系统

    基于AXI VDMA的图像采集系统 转载 2017年04月18日 17:26:43 标签: framebuffer / AXIS / AXI VDMA 2494 本课程将对Xilinx提供的一款IP核 ...

  7. hsqldb

    http://www.hsqldb.org/ HSQLDB (HyperSQL DataBase) is the leading SQL relational database software wr ...

  8. Oracle之函数concat、lpad

    一.引言 程序测试需要生成大量的测试数据,且测试数据有主键,主键自增,于是决定用存储过程来实现,经过半天的查资料终于完成了,记录之,学习之 二.存储过程 格式: CREATE PROCEDURE re ...

  9. python 同时遍历多个变量

    最近在用python的时候,用到遍历多个变量: import sys import math F58=11491939491.7 F=[11429229079.7,11374540753.7,1132 ...

  10. django 模板报错

    "Requested setting TEMPLATE_DEBUG, but settings are not configured. You must either define the ...