iOS 多任务处理中进入后台时线程的行为
在运行一些测试时,我注意到当应用程序(没有后台权限,即 voip、gps 等)进入后台状态时,当时运行的任何后台线程(或并发 NSOperations)似乎都会暂停(未终止) ,当应用程序进入前台时,它们会继续。
我在任何地方都看不到这个线程行为的记录。有谁知道这种行为是否已定义并且可以信赖?
如果重新打开应用程序时线程可以安全地继续,那么不必取消任务或参与任务完成将很有用。特别是对于复杂的操作。
任何信息都会很棒。谢谢!
While running some tests I've noticed that when an app (with no background privileges, i.e. voip, gps, etc) enters the background state, any background threads (or concurrent NSOperations) running at the time seem to be paused (not terminated), and they continue when the app enters the foreground.
I can't see this thread behaviour documented anywhere. Does anyone know if this behaviour is defined and can be counted on?
It would be useful to not have to cancel tasks or get involved in task completion if the thread can safely continue when the app is re-opened. Especially for complicated operations.
Any info would be great. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当非多任务应用程序退出时,它会冻结在当前状态并保留在内存中。但是,如果内存不足,用户从多任务栏关闭它,或者设备关闭,应用程序将在没有警告的情况下终止。您可以相信从后台返回的应用程序将像以前一样继续运行,但您应该在进入后台时保存状态,以防应用程序关闭。
When a non-multitasking app is quit, it is frozen in its current state and left in memory. However, if memory is low, the user closes it from the multitasking bar, or the device is shut down, the app will be terminated without warning. You can trust that an application returning from the background will continue as it was before, but you should save the state when entering the background in case the app is shut down.