Behaviour of threads when entering background in iOS multitasking
Asked Answered
A

1

5

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!

Aback answered 21/1, 2011 at 18:8 Comment(0)
A
9

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.

Altruistic answered 21/1, 2011 at 19:7 Comment(2)
I was aware that the current state (i.e. memory) is persevered, however I am not aware that the various processes/threads themselves are preserved in the same state and the execution is simply halted.Aback
It would appear that the state of the app and it's threads are maintained and continued once it enters the foreground again. The only thing to know is that you cannot guarantee that any delegate calls (i.e. -applicationWillEnterForeground:) will be made before background thread executions start.Aback

© 2022 - 2024 — McMap. All rights reserved.