IOS中AppDelegate类中的方法触发时机-----自定义AppDelegate的写法

@implementation AppDelegate

//当应用程序加载时触发,创建window窗口对象,让对象的window成为程序的主窗口,并且可视.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    //__FUNCTION__方法名__LINE__所在的行数
    NSLog(@"%s,%d",__FUNCTION__,__LINE__);

    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}
//应用程序将要取消活跃状态是触发‘
//使用该方法暂停掉正在执行的任务,让定时器失效,暂停游戏.
- (void)applicationWillResignActive:(UIApplication *)application {
    NSLog(@"%s,%d",__FUNCTION__,__LINE__);
    // 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.
}
//当应用程序进入后台时触发
//释放共享资源,保存用户数据,让timer失效,保存当前程序退出时会替换applicationWillTerminate
- (void)applicationDidEnterBackground:(UIApplication *)application {
    NSLog(@"%s,%d",__FUNCTION__,__LINE__);
    // 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.
}
//当应用程序将要进入前台时触发
//继续进入后台时正在运行的任务,游戏继续进行
- (void)applicationWillEnterForeground:(UIApplication *)application {
    NSLog(@"%s,%d",__FUNCTION__,__LINE__);
    // 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)applicationDidBecomeActive:(UIApplication *)application {
    NSLog(@"%s,%d",__FUNCTION__,__LINE__);
    // 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.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
-(void)dealloc
{
    [_window release];
    [super dealloc];
}
@end

重写AppDelegate

//LODelegate,注意继承

// UIResponder<UIApplicationDelegate>
@interface LODelegatre : UIResponder<UIApplicationDelegate>
@property (retain, nonatomic) UIWindow *window;
@end
#import "LODelegatre.h"

@implementation LODelegatre
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];;
    self.window.backgroundColor = [UIColor yellowColor];
    [self.window makeKeyAndVisible];
    return YES;
}
- (void)dealloc
{
    [_window release];
    [super dealloc];
}
@end
时间: 2024-08-06 20:05:30

IOS中AppDelegate类中的方法触发时机-----自定义AppDelegate的写法的相关文章

C#中Thread类中Join方法的理解(转载)

指在一线程里面调用另一线程join方法时,表示将本线程阻塞直至另一线程终止时再执行      比如 Java代码   using System; namespace TestThreadJoin { class Program { static void Main() { System.Threading.Thread x = new System.Threading.Thread(new System.Threading.ThreadStart(f1)); x.Start(); Console

JAVA中Runtime类以及exec()方法,Process的使用

package ioTest.io1; /* * Runtime:每个 Java 应用程序都有一个 Runtime 类实例,使应用程序能够与其运行的环境相连接. * 这也是jvm实现跨平台的一个重要原因. * 可以通过 getRuntime 方法获取当前运行时. * API分析: * public class Runtime extends Object * 每个 Java 应用程序都有一个 Runtime 类实例,使应用程序能够与其运行的环境相连接. * 可以通过 getRuntime 方法获

Java中主类中定义方法加static和不加static的区别

Java中主类中定义方法加static和不加static的区别(前者可以省略类名直接在主方法调用,后者必须先实例化后用实例调用) 知识点:1.Getter and Setter 的应用 2.局部变量与成员变量(也可叫做全局变量) 3.Static关键字的用法 a.成员变量被static修饰后的所有类的共享属性 b.方法被static修饰之后,在本类内调用的类名省略问题;以及不用Static,即使在本类内也必须先实例化 4.This关键字的用法 this:是当前类的对象引用.简单的记,它就代表当前

C 中SqlParameter类的使用方法小结

C# 中SqlParameter类的使用方法小结 在c#中执行sql语句时传递参数的小经验 1.直接写入法: 例如: int Id =1; string Name="lui"; cmd.CommandText="insert into TUserLogin values("+Id+",'"+Name+"')"; 因为Id是数值,所以在传递的时候只需要在sql字符串中用"+Id+"即可实现,而   Name是

Java中Object类的公有方法

HashCode();wait();notify();equals();getClass();toString();clone();finalize(); 这里只是简单介绍一下其中的几个函数: HashCode(): * As much as is reasonably practical, the hashCode method defined by * class {@code Object} does return distinct integers for distinct * obje

关于Java中String类的hashCode方法

首先来看一下String中hashCode方法的实现源码 1 public int hashCode() { 2 int h = hash; 3 if (h == 0 && value.length > 0) { 4 char val[] = value; 5 6 for (int i = 0; i < value.length; i++) { 7 h = 31 * h + val[i]; 8 } 9 hash = h; 10 } 11 return h; 12 } 在Stri

关于在C#中对类中的隐藏基类方法和重写方法的理解

最近在学习C#,在C#中的类看到重写和隐藏基类的方法这些概念.才开始感觉自己不是很理解这些概念.也区分不开这些概念.通过自己的查找资料和练习后.慢慢的理解了类中的隐藏和重写这个概念.在C#中只有在基类定义了一些虚方法才能在派生类中重写基类中的虚方法.但是如果在派生类中使用隐藏方法,就不用在基类中定义虚方法.虚方法和重写实现的功能感觉是差不多的.都是在派生类中改变了基类中的方法,但是两者还是有质的区别,概念的性质也是不一样的.   重写是指:将基类中的方法替换掉,也就是抹掉基类中的原有方法,在派生

java中String类中的replace方法

package stringTest; public class StringDemo2 { public static void main(String[] args) { String s = "acvbb"; String s1 = new String("acvbb"); String s2 = s.replace("a", "X"); String s3 = s1.replace("a", &qu

JAVA中Object类中的equals方法补充

Object类中的equals方法: 无论new多少个对象,当使用 "= =" 来判断的时候,是判断内存地址.判断回事false 若是需要进行对象之间的判断,则需要重写equals方法: public boolean equals(Object obj)//obj是传入的形式参数(对象) { if (obj == null)//判断对象是否为空 { return false;//空则返回false } else { if ( obj instanceof cat)//判断这个传入参数(