4
  1. User has my app open.
  2. They hit the home button, resulting in my app closing and going into a "saved state".
  3. Users uses his device for other things.
  4. User opens up my app again, resuming from where he left off.

How, in my code, do I detect that the user has resumed from the saved state? Is there a specific iOS4 multitasking NSNotification that I can attach to?

Ethan Allen
  • 14,425
  • 24
  • 101
  • 194

3 Answers3

0

You can use the app delegate methods to get you up and running if the system terminates your app is while it is in the background.

If your app isn't terminated, then observing the UIApplicationDidEnterBackgroundNotification notification will be helpful. It will allow you to do any viewController specific state saving and cleanup. You can use this to do quick clean up. i.e. freeze dry any lazily created instance variables in order to make your app as small as possible in terms of memory foot print while it is in the background state.

Registering for this notification allows you to restore state UIApplicationWillEnterForegroundNotification

Make sure you are careful to remove your object as an observer though.

timthetoolman
  • 4,613
  • 1
  • 22
  • 22
0

AppDelegate.m:

- (void)applicationDidEnterBackground:(UIApplication *)application {
    NSLog(@"Application did enter background.");
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    NSLog(@"Application did become active.");
}
gotnull
  • 26,454
  • 22
  • 137
  • 203