在通过iOS-4多任务进行快速上下文切换时,我对保存应用程序的最后一个状态有疑问。
应用程序必须手动将最后一个状态保存在"- (void)applicationDidEnterBackground:(UIApplication *)应用程序“中吗?或者iOS-4会解决这个问题?
视频中提到了如下内容:
-(void)applicationDidEnterBackground:(UIApplication *)application {
// save app state
[self saveState];
// reduce memory usages
....
// prepare UI
....
// close listening sockets
....
}提前谢谢你,
Sunil
发布于 2010-07-02 21:11:52
一旦你的应用程序进入后台,就不能保证它会回到前台。它可以在任何时候被终止,而不需要任何形式的通知。因此,进入后台时,您希望保存状态或冒着丢失状态的风险。
引用苹果的话(来源:http://developer.apple.com/iphone/library/documentation/iphone/conceptual/iphoneosprogrammingguide/BackgroundExecution/BackgroundExecution.html):
在移动到后台之前保存应用程序状态。在内存不足的情况下,后台应用程序将从内存中清除以释放空间。挂起的应用程序会先被清除,在清除之前不会通知应用程序。因此,在移动到后台之前,应用程序应该始终保存足够的状态信息,以便以后在必要时进行自我重构。将应用程序恢复到以前的状态也为用户提供了一致性,在重新启动应用程序时,用户将短暂地看到应用程序主窗口的快照。
发布于 2010-07-02 21:19:25
应用程序必须手动将最后一个状态保存在"- (void)applicationDidEnterBackground:(UIApplication *)
“中吗?或者iOS-4会解决这个问题?
是的,如果你想要你的应用在被杀死后恢复,你需要在这里手动保存状态。
发布于 2011-09-07 20:42:56
在进入background/terminate之前,你应该在你的应用委托中使用这两个方法来保存当前状态。
- (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 throttle down OpenGL ES frame rates.
Games should use this method to pause the game.
*/
}
- (void)applicationWillTerminate:(UIApplication *)application {
/*
Called when the application is about to terminate.
See also applicationDidEnterBackground:.
*/
}https://stackoverflow.com/questions/3165434
复制相似问题