0

I am working a multitasking app which continues for a while after being sent to the background. I noticed that the drawRect methods in one of the UIView gets called constantly when the app is in the background. This drawRect method is responsible for updating the user interface while the app works.

What is the best practice for this? I don't want to be wasting CPU cycles drawing something that the user won't see.

XCool
  • 976
  • 11
  • 32

1 Answers1

1

Maybe the answer to this question might help you out: Check if iOS app is in background

Check if the app is running in the background, and if so... don't draw anything.

Community
  • 1
  • 1
Paul Peelen
  • 10,073
  • 15
  • 85
  • 168
  • Thanks for the quick comments. I've thought of that too. In fact, I was thinking of using `[UIApplication sharedApplication].applicationState` to check if the app is currently backgrounded, and if yes, return from the drawRect method without doing anything. Are there any other best practices? – XCool Apr 26 '12 at 14:09
  • Well, I think you might be able to check if the view in question is visible or not. That way you would also save CPU usage if the app is active but the view not shown (might not be needed to draw on a view which issn't shown?) http://stackoverflow.com/questions/2777438/how-to-tell-if-uiviewcontrollers-view-is-visible/2777460#2777460 – Paul Peelen Apr 26 '12 at 14:55