首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在快速上下文切换时保存当前状态- iOS4

在快速上下文切换时保存当前状态- iOS4
EN

Stack Overflow用户
提问于 2010-07-02 19:59:34
回答 3查看 700关注 0票数 0

在通过iOS-4多任务进行快速上下文切换时,我对保存应用程序的最后一个状态有疑问。

应用程序必须手动将最后一个状态保存在"- (void)applicationDidEnterBackground:(UIApplication *)应用程序“中吗?或者iOS-4会解决这个问题?

视频中提到了如下内容:

代码语言:javascript
复制
-(void)applicationDidEnterBackground:(UIApplication *)application {
   // save app state
   [self saveState];

   // reduce memory usages
   ....

   // prepare UI
   ....

   // close listening sockets
   ....
}

提前谢谢你,

Sunil

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2010-07-02 21:11:52

一旦你的应用程序进入后台,就不能保证它会回到前台。它可以在任何时候被终止,而不需要任何形式的通知。因此,进入后台时,您希望保存状态或冒着丢失状态的风险。

引用苹果的话(来源:http://developer.apple.com/iphone/library/documentation/iphone/conceptual/iphoneosprogrammingguide/BackgroundExecution/BackgroundExecution.html):

在移动到后台之前保存应用程序状态。在内存不足的情况下,后台应用程序将从内存中清除以释放空间。挂起的应用程序会先被清除,在清除之前不会通知应用程序。因此,在移动到后台之前,应用程序应该始终保存足够的状态信息,以便以后在必要时进行自我重构。将应用程序恢复到以前的状态也为用户提供了一致性,在重新启动应用程序时,用户将短暂地看到应用程序主窗口的快照。

票数 0
EN

Stack Overflow用户

发布于 2010-07-02 21:19:25

应用程序必须手动将最后一个状态保存在"- (void)applicationDidEnterBackground:(UIApplication *)

“中吗?或者iOS-4会解决这个问题?

是的,如果你想要你的应用在被杀死后恢复,你需要在这里手动保存状态。

票数 0
EN

Stack Overflow用户

发布于 2011-09-07 20:42:56

在进入background/terminate之前,你应该在你的应用委托中使用这两个方法来保存当前状态。

代码语言:javascript
复制
  - (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:.
     */
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3165434

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档