UIApplicationDelegateDemo--应用程序前台、后台分析
2012-03-14 08:53
477 查看
建立UIApplicationDelegateDemo主要用来明确应用程序进入前台、按home键进入后台以及在此唤醒进入前台函数的调用顺序。
程序运行后,调用的函数如下:
点击home键后:
在此点击程序,程序返回主界面:
// // AppDelegate.h // UIApplicationDelegateDemo // // Created by Fox on 12-3-14. // Copyright (c) 2012年 __MyCompanyName__. All rights reserved. // #import <UIKit/UIKit.h> @class ViewController; @interface AppDelegate : UIResponder <UIApplicationDelegate>{ } @property (strong, nonatomic) UIWindow *window; @property (strong, nonatomic) ViewController *viewController; @end
// // AppDelegate.m // UIApplicationDelegateDemo // // Created by Fox on 12-3-14. // Copyright (c) 2012年 __MyCompanyName__. All rights reserved. // #import "AppDelegate.h" #import "ViewController.h" @implementation AppDelegate @synthesize window = _window; @synthesize viewController = _viewController; - (void)dealloc { [_window release]; [_viewController release]; [super dealloc]; } /* *当程序完成载入,并且可能有额外的启动选项时被调用,用于程序的初始化 */ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSLog(@"Fox:didFinishLaunchingWithOptions"); self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; return YES; } /* *应用程序初始化完成后,程序转为激活状态时被调用 */ - (void)applicationDidBecomeActive:(UIApplication *)application { NSLog(@"Fox:applicationDidBecomeActive"); /* 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. */ } /* *应用程序转为后台(非激活)状态时被调用,即按home键后先调用该方法 */ - (void)applicationWillResignActive:(UIApplication *)application { NSLog(@"Fox:applicationWillResignActive"); } /* *程序转到后台后,调用此方法,若想在后台运行程序,在此处添加. *应用此方法来释放资源,保存数据,使计时器停止,存储应用程序状态和信息 */ - (void)applicationDidEnterBackground:(UIApplication *)application { NSLog(@"Fox:applicationDidEnterBackground"); } /* *应用程序将要从后台进入前台时调用带方法 */ - (void)applicationWillEnterForeground:(UIApplication *)application { NSLog(@"Fox:applicationWillEnterForeground"); /* 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. */ } /* *应用程序将要终止时调用 */ - (void)applicationWillTerminate:(UIApplication *)application { NSLog(@"Fox:applicationWillTerminate"); /* Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. */ } @end
程序运行后,调用的函数如下:
点击home键后:
在此点击程序,程序返回主界面:
相关文章推荐
- UIAPPLICATIONDELEGATE 代理函数调用的时间(应用程序生命周期)
- UIApplicationDelegate 包含下面几个函数监控应用程序状态的改变:
- UIApplicationDelegate 代理函数调用的时间(应用程序生命周期)
- UIApplicationDelegate分析小结
- UIApplicationDelegate详解 -- iOS应用程序周期
- UIApplicationDelegate 应用程序状态
- iOS 【应用程序app运行原理-UIApplication-AppDelegate.m-UIApplicationMain】
- UIApplicationDelegate 代理函数调用的时间(应用程序生命周期)
- UIAPPLICATIONDELEGATE 代理函数调用的时间(应用程序生命周期)
- 如何获得应用程序的 UIApplicationDelegate
- UIApplicationDelegate分析小结
- UIApplicationDelegate 代理函数调用的时间(应用程序生命周期)
- UIAPPLICATIONDELEGATE 代理函数调用的时间(应用程序生命周期)
- UIApplicationDelegate 代理函数调用的时间(应用程序生命周期)
- UIApplicationDelegate 包含下面几个函数监控应用程序状态的改变
- [转]UIApplicationDelegate分析小结
- 百度地图拖拽设置自定义坐标demo3个(后台添加、修改,前台显示)
- Android判断应用程序从后台回到前台
- Android判断当前应用程序处于前台还是后台的两种方法
- Fresco 源码分析(四) 后台数据返回到前台的处理