IOS程序生命周期

        刚接触IOS的学习,做点小笔记,总结下,加深下记忆。第一篇文章讲述IOS程序的生命周期也就是类似于Android Activity的生命周期,但是在IOS中只有在AppDelegate.h文件中存在生命周期,而在单独的Control中不存在生命周期的使用,也就是相当于Android的Application和Activity生命周期的结合体。废话不多说下面进入正题。
        先解释下AppDelegate的各个方法的意义。

一、application: didFinishLaunchingWithOptions:
        此方法在程序启动以后之后执行,只有在第一次程序启动之后才会执行,相当于Android中的onCreate。

//只有在程序启动第一次才会调用该方法
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    return YES;
}

二、applicationDidBecomeActive:
        此方法表示程序已经获得焦点,每次进入前台最后调用的就是该方法,相当于Android中的onResume。

//表示程序获得到焦点,每次程序前台后最后执行该方法
- (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.
}

三、applicationWillEnterForeground:
        该方法表示程序进入前台,启动程序或进入程序后触发的方法,相当于Android的onStart。

//程序即将进入前台
- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

四、applicationWillResignActive:
        该方法表示程序失去焦点,程序进入后台第一个触发的方法,相当于Android中的onPause。

//程序将要失去焦点
- (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 invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

五、applicationDidEnterBackground:
        该程序表示程序即将进入后台,进入后台最后执行的方法,相当于Android的onStop。

//程序即将进入后台
- (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.
}

六、applicationWillTerminate:
        该方法表示程序即将终止,相当于Android中的Application的onDestory的方法。

//程序即将终止的方法
- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

七、applicationDidReceiveMemoryWarning
        该方法表示程序内存不足时,IOS系统发送警告执行的方法。

//程序接受到内存不足的通知执行的方法
-(void)applicationDidReceiveMemoryWarning:(UIApplication *)application{
}

八、实际用户操作生命周期的调用
        上面简要描述了AppDelegate中各个方法的作用,下面介绍用户在实际操作软件情况下各个函数的执行情况。

(1)第一次进入程序
1.application: didFinishLaunchingWithOptions:
    ----程序启动
2.applicationDidBecomeActive:
    ----程序获得焦点

(2)程序按下Home键(或者切换到其他程序)
1.applicationWillResignActive:
    ----程序将要失去焦点
2.applicationDidEnterBackground:
    ----程序进入后台

(3)重新进入程序
1.applicationWillEnterForeground:
    ----程序进入前台
2.applicationDidBecomeActive:
    ----程序获得焦点

(4)下拉状态栏
1.applicationWillResignActive:
    ----程序将要失去焦点
    ----注:程序只是失去了焦点,而不会步入后台

(5)状态栏收回
1.applicationDidBecomeActive:
    ----程序获得焦点

(6)双击Home关闭程序
1.applicationWillResignActive:
    ----程序将要失去焦点
2.applicationDidEnterBackground:
    ----程序进入后台
3.applicationWillTerminate:
    ----程序将要终止

        以上就是程序在实际用户操作下可能发生的几种情况,开发者可自行在对应的方法下执行自己的代码。

参考资源链接:[电气工程的随机过程:概率与统计](https://wenku.youkuaiyun.com/doc/5e53mssvjz?utm_source=wenku_answer2doc_content) 大数定律和中心极限定理是概率论中的两个核心概念,它们在电气工程领域中有着广泛的应用。为了帮助你深入理解并应用这两个定理解决实际问题,我建议参考《电气工程的随机过程:概率与统计》一书。这本书详细介绍了这两个定理的理论基础以及在电气工程中的具体应用方法。 大数定律描述了当实验次数足够多时,样本均值会以极高的概率接近期望值。在电气工程中,这一性质可以用来分析大量重复测量数据的稳定性和可靠性。例如,在信号处理领域,大数定律可以应用于噪声的统计分析,帮助工程师评估在一定数量的测量后,噪声的平均值是否收敛,从而设计出更为稳定的信号处理系统。 中心极限定理则表明,即使原始数据分布不是正态分布,只要样本数量足够大,样本均值的分布接近正态分布。在电气工程的许多实际问题中,如无线通信、雷达信号检测等,中心极限定理提供了进行概率推断和信号估计的理论依据。例如,在设计通信系统的信号检测器时,可以通过中心极限定理推断出信号检测器在不同噪声水平下的性能,从而优化系统的检测阈值。 为了将大数定律和中心极限定理应用于电气工程项目,你需要进行以下几步: 1. 确定问题的随机性质,并识别出需要分析的随机变量。 2. 收集足够量的数据或进行重复实验,以确保大数定律的适用条件得到满足。 3. 应用中心极限定理,确定样本均值的分布,并估计其参数。 4. 根据推断出的分布特征,进行工程设计或系统优化。 通过阅读《电气工程的随机过程:概率与统计》,你不仅可以获得关于如何应用大数定律和中心极限定理的深入理解,还能学习到其他相关的概率论和统计学知识,以及随机过程在电气工程中的应用实例。这些知识将帮助你在未来遇到类似问题时能够迅速且有效地运用统计学方法进行分析和决策。 参考资源链接:[电气工程的随机过程:概率与统计](https://wenku.youkuaiyun.com/doc/5e53mssvjz?utm_source=wenku_answer2doc_content)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值