IOS应用的状态
not running
inactive
active
background
suspened
在应用状态跃迁过程中 ios系统会回调AppDelegate 中的一些方法.
<pre>
<code>
//应用启动并进行初始化时,会调用该方法并发出通知
//这个阶段会实例化根视图控制器
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
NSLog(@"application didFinishLaunchingWithOptions..... --> app init");
return YES;
}
//app从活动状态(active) 进入 非活动状(inactive)态调用此方法
-
(void)applicationWillResignActive:(UIApplication *)application {
NSLog(@"applicationWillResignActive..... active-->inactive");
}
//app进入后台时进行调用
- (void)applicationDidEnterBackground:(UIApplication *)application {
NSLog(@"applicationDidEnterBackground --> 进入background");
}
//app进入到前台 但是处于非活动状态时调用
- (void)applicationWillEnterForeground:(UIApplication *)application {
NSLog(@"applicationWillEnterForeground --> 进入inactive");
}
//应用进入active 活动状态时候 进行调用
- (void)applicationDidBecomeActive:(UIApplication *)application {
NSLog(@"applicationDidBecomeActive -->进入active");
}
//应用被终止时调用
//内存清除时除外
- (void)applicationWillTerminate:(UIApplication *)application {
NSLog(@"applicationWillTerminate --> app stop");
}
</code>
</pre>
结合一些场景:
点击icon启动app

启动场景跃迁的过程
点击home键 app退出场景
app处于 active状态 点击home 或其它应用导致当前应用中断,该场景的跃迁状态分2种
1.可在后台运行或挂起

2.不可再后台运行或挂起

任务列表中选择app 重新打开
从挂起到重新运行

内存清除 app被干掉
处于挂起状态的app 如果系统发出内存警告 该应用就会被清除掉

网友评论