iOS开发:应用生命周期
- 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开发:应用生命周期的更多相关文章
- 【iOS开发】iOS对UIViewController生命周期和属性方法的解析
iOS对UIViewController生命周期和属性方法的解析 一.引言 作为MVC设计模式中的C,Controller一直扮演着项目开发中最重要的角色,它是视图和数据的桥梁,通过它的管理,将数据有 ...
- (转)iOS应用程序生命周期(前后台切换,应用的各种状态)详解
原文:http://blog.csdn.net/totogo2010/article/details/8048652 iOS应用程序生命周期(前后台切换,应用的各种状态)详解 分类: ...
- iOS对UIViewController生命周期和属性方法的解析
目录[-] iOS对UIViewController生命周期和属性方法的解析 一.引言 二.UIViewController的生命周期 三.从storyBoard加载UIViewController实 ...
- 转:iOS应用程序生命周期(前后台切换,应用的各种状态)详解
iOS应用程序生命周期(前后台切换,应用的各种状态)详解 分类: iOS开发进阶2012-10-08 15:35 42691人阅读 评论(30) 收藏 举报 iosapplication任务anima ...
- android开发之生命周期
android开发之生命周期 一:Activity的生命周期: 这几天了了解了安卓Activity的生命周期,对于生命周期有了大概的理解: 一个Activity的生命周期也就是Activity从生成到 ...
- Android开发——Activity生命周期
Android开发--Activity生命周期 Activity作为四大组件之首,也是使用最频繁的一种组件.本文将主要讲解Activity生命周期,包括正常情况下的Activity生命周期和异常情况下 ...
- 浅尝Spring注解开发_Bean生命周期及执行过程
Spring注解开发 浅尝Spring注解开发,基于Spring 4.3.12 包含Bean生命周期.自定义初始化方法.Debug BeanPostProcessor执行过程及在Spring底层中的应 ...
- iOS - ViewController的生命周期
iOS SDK中提供很多原生的ViewController,大大提高了我们的开发效率:那么下面我们就根据开发中我们常用的ViewController谈一谈它的生命周期: (一)按照结构和用法可以对iO ...
- iOS控制器的生命周期分析和使用
转自http://blog.csdn.net/qijianli/article/details/7826979 iOS的SDK中提供很多原生ViewController,大大提高了我们的开发效率,下面 ...
- [转]iOS应用程序生命周期(前后台切换,应用的各种状态)详解
转载地址:http://blog.csdn.net/totogo2010/article/details/8048652 iOS的应用程序的生命周期,还有程序是运行在前台还是后台,应用程序各个状态的变 ...
随机推荐
- highCharts 电流表、电压表
var highChartsSettingV = { chart: { margin: [5, 2, 5, 8], type: 'gauge', plotBorderWidth: 1, plotBac ...
- 【转】HTTP-only Cookie 脚本获取JSESSIONID的方法
彻底避免xss攻击的方法. 别人可以通过注入js脚本获取你的session cookie,如果幸运的话还可以获取通过js遍历你的dom树获取你的用户的用户名和密码. 如果只是通过正则表达式验证输入的话 ...
- FMS (端口问题)如何穿透防火墙
转自http://www.cnblogs.com/zhchongyao/archive/2010/01/22/1653803.html 先是管理端口,就是fms2_console文件连接到server ...
- Basic Concepts of International Trade
The international trade structure is a reflection of worldwide economic development, industrial stru ...
- SHELL syntax error:unexpected end of file 提示错误
SHELL syntax error:unexpected end of file 提示错误 if [ -n "$1" ] then " else " fi e ...
- 数字式PID控制的应用总结
PID控制是一个二阶线性闭环控制器,通过调整比例.积分和微分三项参数,使得大多数的工业控制系统获得良好的闭环控制性能.PID控制优点:a. 技术成熟,b. 易被人们熟悉和掌握,c. 不需要建立数学模型 ...
- 【BZOJ】【2194】快速傅里叶之二
FFT c[k]=sigma a[i]*b[i-k] 这个形式不好搞…… 而我们熟悉的卷积的形式是这样的 c[k]=sigma a[i]*b[k-i]也就是[下标之和是定值] 所以我们将a数组反转一下 ...
- 同一机器 部署 两个 jboss
当jboss和oracle在同一机器上时,通常oracle占用8080端口,这时只需要去修改\deploy\jbossweb-tomcat50.sar\server.xml中.当在同一台机器上运行两个 ...
- 如何监控业务的响应速度?Cloud Insight SDK 实践分享
一直在说 Cloud Insight 是数据聚合平台,可以用 SDK 和 API 实现业务监控,如今不拿出点实践人们恐怕是不能信服.那今天本文就先简单介绍一下 SDK 可以应用在哪些方面,再举个真实用 ...
- Amazon Interview Question: Design an OO parking lot
Design an OO parking lot. What classes and functions will it have. It should say, full, empty and al ...