Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Behaviour of threads when entering background in iOS multitasking

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!

like image 358
Michael Waterfall Avatar asked Jan 21 '11 18:01

Michael Waterfall


1 Answers

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.

like image 80
ughoavgfhw Avatar answered Nov 11 '22 18:11

ughoavgfhw