tags:

views:

64

answers:

2

Hey All,

While going through the iOS-4 Multitasking for fast context switching, I have a doubt regarding save last state of application.

Do applications have to manually save the last state in "- (void)applicationDidEnterBackground:(UIApplication *)application"? Or iOS-4 will take care of it?

In the video it's mentioned as follows:

-(void)applicationDidEnterBackground:(UIApplication *)application {
   // save app state
   [self saveState];

   // reduce memory usages
   ....

   // prepare UI
   ....

   // close listening sockets
   ....
}

Thanks in advance,

Sunil

A: 

Once your application has entered background, there's no guarantee it will ever come back to the foreground. It may at any point in time be terminated, without notification of any kind. Thus, entering background, you want to save the state or risk losing it.

To quote Apple (source: http://developer.apple.com/iphone/library/documentation/iphone/conceptual/iphoneosprogrammingguide/BackgroundExecution/BackgroundExecution.html),

Save your application state before moving to the background. During low-memory conditions, background applications are purged from memory to free up space. Suspended applications are purged first, and no notice is given to the application before it is purged. As a result, before moving to the background, an application should always save enough state information to reconstitute itself later if necessary. Restoring your application to its previous state also provides consistency for the user, who will see a snapshot of your application’s main window briefly when it is relaunched.

Kalle
A: 

Do applications have to manually save the last state in "- (void)applicationDidEnterBackground:(UIApplication *)application"? Or iOS-4 will take care of it?

Yes, if you want your app to restore after it's been killed, you need to manually save state here.

kubi