How to Prevent Your Application from Being Placed into the Background

September 7, 2010

By default, when running on a device that supports multitasking, if the user quits the application (pressing the Home button), the application will be notified and moved to the background. This is nice as the response time when the user requests the application again is generally very quick, not to mention the application resumes in the same place/state as when it exited.

Even with this built-in convenience, they are times when this default behavior may not be ideal. For example, depending on the application, it may require a fair amount of additional development time to properly manage this state change. In such cases, simply quiting the application may be preferred.

UIApplicationExitsOnSuspend

To request the application exit rather than be suspended, add the key UIApplicationExitsOnSuspend to the application’s plist file. The figure below shows how this looks if you edit the plist as an XML file.

<plist version="1.0">
<dict>
  ...
<key>UIApplicationExitsOnSuspend</key>
<true/>
  ...
</dict>
</plist>

If you prefer to edit the file using the Property List editor, the change would look as follows:

Application Shutdown

If you’ve added the plist entry above, just as on non-multitasking devices, when the user taps the Home key the method applicationWillTerminate: in the application delegate will be called. You have somewhere in the neighborhood of 5 seconds to save any pertinent information before the application is terminated.

Although there are times to use this approach, it is generally recommended for the best user experience to design/develop your applications to manage being placed into the background.

3 comments

Thank you. This is exactly what I am looking for. Thank you so much for the information.

by abatalk on Aug 18, 2011. Reply #

hey!
in which plist file should i add these lines? i mean.. there is ann application folder.. so inside it, there are a few plist files. which? THANKS ALOT!!!

by Evanee on Sep 30, 2011. Reply #

Add this to the application specific plist, that is, the same plist that has the bundle display name, executable file, etc

by John Muchow on Sep 30, 2011. Reply #

Leave a Comment