How do I identify if the app was in the background when the home button was clicked and not by external events (sms, call, video call)?
Asked
Active
Viewed 3,237 times
2
-
2Oy; no matter how often I ask, I never seem to learn that I shouldn't: Why do you need to know this? – Williham Totland Jul 08 '11 at 13:30
-
1@Williham Totland that is out of the scope of this question. – Jul 08 '11 at 13:33
-
@WTP: Not necessarily: The Why informs the How. – Williham Totland Jul 08 '11 at 13:42
-
@WTP: Case in point: http://stackoverflow.com/questions/6625452/iphone-home-button-pressed – Williham Totland Jul 08 '11 at 13:54
2 Answers
4
If the application is sent to background,
applicationDidEnterBackground
will be getting called.
If it is by sms, call , video call, then,
applicationWillResignActive
will be getting called first. U can identify with that.

Ilanchezhian
- 17,426
- 1
- 53
- 55
-
In my app has a button that opens the browser and my application was for background. I just want to close the app when the home button is clicked. Thanks for helping me. – Wesley Belarmino Jul 08 '11 at 13:50
-
To close the app, just call exit(0)... Before that if u want to store anything like settings, save it... – Ilanchezhian Jul 08 '11 at 15:01
0
AFAIK there's no way. Look at UIApplicationDelegate documentation, you'll see :
- (void)applicationWillResignActive:(UIApplication *)application
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.
There's apparently no way to distinguish an interruption (SMS, call) or an exit (by pushing the Home button).