0

The Apple docs for this event states:

This method is called to let your application know that it is about to move from the 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. An application in the inactive state continues to run but does not dispatch incoming events to responders.

I am seeing behavior that is at variance with the last sentence. If I run an app under the XCode debugger that collects and logs data in response to a timer firing, the data collection and logging continues indefinitely if I press the Sleep/Wake button to put the device to sleep.

However, if I run the app "normally" (ie, not in the XCode debugger) then data collection and logging stops almost immediately after the device is slept.

The Apple docs also say (emphasis mine)

You should use this method to pause ongoing tasks, disable timers and throttle down OpenGL ES frame rates.

But doesn't really explain why timers should be disabled.

I'm trying to figure out if the observed behavior (the inactive state seems to stop my timer, and/or possibly the entire app) is a bug or not, or if the docs are wrong about an application running while inactive, or why the behavior of the app under the debugger is different from the "real world" behavior.

Any help or clarification would be appreciated.

software evolved
  • 4,314
  • 35
  • 45

2 Answers2

0

Read about the various application states for insight into this. Apps don't usually stay in the inactive state for very long, but switch to either background or suspsended states.

Caleb
  • 124,013
  • 19
  • 183
  • 272
  • Caleb, I had read that doc which states "The only time [an app] stays inactive for any period of time is when the user locks the screen" which is the case I'm describing here. – software evolved Apr 13 '11 at 16:54
  • Doesn't say what "any period of time" might be, though. I don't think you can count on staying inactive under any circumstances. – Caleb Apr 13 '11 at 16:59
0

I (finally!) found a thread that seems to explain what I'm seeing:

What happens to an iPhone app when iPhone goes into stand-by mode?

It appears the difference in behaviors isn't tied to XCode, but is instead because the device is attached via USB (to allow debugging), so iOS never sleeps after the screen is locked because it's plugged in and charging.

If the device is not plugged in, then a short time after the screen is locked (approx 20 seconds), the device sleeps: all activity on the main CPU halts.

So the Apple docs aren't wrong, just incomplete in not stating the inactive -> slept transition that takes place.

(Should I delete this question?)

Community
  • 1
  • 1
software evolved
  • 4,314
  • 35
  • 45