0

When I click the home button on the device. This is a part of my delegate:

- (void)applicationWillResignActive:(UIApplication *)application
{
    NSLog(@"resign active");
    //[[NSThread mainThread] cancel];
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
    NSLog(@"enter background");
    //[[NSThread mainThread] cancel];
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    NSLog(@"enter foreground");
    //[[NSThread mainThread] cancel];
}
- (void)applicationWillTerminate:(UIApplication *)application
{
    NSLog(@"terminate");
    //[[NSThread mainThread] cancel];
}

I uses NSLog to understand which method are called when I click the Home Button. This is output in console.

2012-01-20 15:55:55.853 MyApp[5955:11f03] enter background
2012-01-20 15:55:55.855 MyApp[5955:11f03] terminate
Program ended with exit code: 0

So, when I click on app in background (clicking two time the home button), it launchs again showing the first image and then my first uiviewcontroller.

In which way I can resolve it, and resume app from uiviewcontroller that was on the top when user clicks home button?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Jayyrus
  • 12,961
  • 41
  • 132
  • 214

1 Answers1

4

Check your info.plist file and make sure that "Application does not run in background" is not checked.

The image below shows the option in state "on", so that when the user press the home button, the app is effectively finalized.

info.plist configuration

This is how Apple describes that option:

UIApplicationExitsOnSuspend

UIApplicationExitsOnSuspend (Boolean - iOS) specifies that the application should be terminated rather than moved to the background when it is quit. Applications linked against iOS SDK 4.0 or later can include this key and set its value to YES to prevent being automatically opted-in to background execution and application suspension. When the value of this key is YES, the application is terminated and purged from memory instead of moved to the background. If this key is not present, or is set to NO, the application moves to the background as usual.

This key is supported in iOS 4.0 and later.

Community
  • 1
  • 1
sergio
  • 68,819
  • 11
  • 102
  • 123
  • if i leave code like post, NSlog says me 2012-01-20 16:11:12.170 TrovaChiavi-Pro[6005:11f03] resign active 2012-01-20 16:11:12.172 TrovaChiavi-Pro[6005:11f03] enter background, OK, but when i resume app from background, start image continues to show. why? – Jayyrus Jan 20 '12 at 15:12
  • are you still getting the "terminate" log? – sergio Jan 20 '12 at 15:20
  • an explanation could be that your app is killed while in the background because of low memory; I would suggest putting a trace log in `didFinishLaunchingWithOptions` to check whether the app is effectively killed... have you had a look at what happens in the simulator? – sergio Jan 20 '12 at 15:56