Screw Multitasking: How To Make Your iOS 4 Apps Exit For Real

This post is in response to a question on the iPhone Dev SDK forums about how to make your apps not run in the background now that multitasking has finally appeared on the iPhone.

Multi-tasking can be great, but it has added some complexity to programming on the iPhone.  For many apps there really is no advantage. For instance, does the “That’s What She Said” button really need to stay in memory?

It’s some added complexity that programmers don’t need.. some of the more complex memory intensive apps will just exit anyways, and programming the app to suspend can be a highly complicated task.

Fortunately there is a simple way to make your iOS 4 apps terminate for real when the user taps the home button.

This is a simple process:

  1. Open your info.plist file
  2. Add The Key UIApplicationExitsOnSuspend or Select Application does not run in background
  3. Set the new key to YES or Fill in the tick box

Now your applicationwillterminate: method will be run when the user taps the home key, and your app will exit for real.

DeliciousTwitterTechnoratiFacebookLinkedInEmail

Submit A Resource

Have you created a useful tutorial, library or tool for iOS development that you would like to get in front of our 300,000+ monthly page views from iOS developers?

You can send a Tweet to @maniacdev on Twitter or submit the url here.

The resources we feel will appeal to our readers the most will be posted on the front page.

  • http://www.Vellios.com Nick Vellios

    Nice! Thanks. I may be linking to this shortly. :)

  • http://www.Vellios.com Nick Vellios

    Nice! Thanks. I may be linking to this shortly. :)

  • Pingback: Tip: Quit In iOS4 at Under The Bridge

  • Pingback: FlexiCoder Blog » Blog Archive » Truly quit app under iOS4

  • Al Ferber

    I could not get info,plist to accept the string “UIApplicationExitsOnSuspend”, but in the dropdown list of available keys I came across “application does not run in background.” I selected it, and now my app terminates and re-launches normally (ie, as it did before OS4).

    Thanks for the tip — I would not otherwise have thought to look to info.plist for a solution.

    Regards,

    Al

  • Al Ferber

    I could not get info,plist to accept the string “UIApplicationExitsOnSuspend”, but in the dropdown list of available keys I came across “application does not run in background.” I selected it, and now my app terminates and re-launches normally (ie, as it did before OS4).

    Thanks for the tip — I would not otherwise have thought to look to info.plist for a solution.

    Regards,

    Al

  • John

    That is weird Al (hmm.. just noticed I typed weird Al), just worked for me again, I didn’t notice that selection.. enterinng UIApplicationExitsOnSuspend should do the same but I will add that little tidbit into the article as it’s easier.

  • John

    That is weird Al (hmm.. just noticed I typed weird Al), just worked for me again, I didn’t notice that selection.. enterinng UIApplicationExitsOnSuspend should do the same but I will add that little tidbit into the article as it’s easier.

  • Al Ferber

    Hi John. I get called weird Al a lot — mainly by my relatives. Thanks for getting back.

    First time on this site — think I’ll check it out now!

    Regards,

    Al

  • Al Ferber

    Hi John. I get called weird Al a lot — mainly by my relatives. Thanks for getting back.

    First time on this site — think I’ll check it out now!

    Regards,

    Al

  • Jon

    My app still remains in memory after adding UIApplicationExitsOnSuspend to the plist. The applicationWillTerminate method is now being called (it was not before adding the new key) but applicationDidEnterBackground is called as well. And, my app remains in the task window after double tapping the home-key. Should applicationDidEnterBackground be called? Thanks for any help.

  • Jon

    My app still remains in memory after adding UIApplicationExitsOnSuspend to the plist. The applicationWillTerminate method is now being called (it was not before adding the new key) but applicationDidEnterBackground is called as well. And, my app remains in the task window after double tapping the home-key. Should applicationDidEnterBackground be called? Thanks for any help.

  • Jon

    Okay, I think I misunderstood the expected behavior. It looks like when I use UIApplicationExitsOnSuspend my app does exit memory but the app icon remains in the task window (after double tapping the home-key). I saw the icon in the task window and assumed it was still running in the background.

  • Jon

    Okay, I think I misunderstood the expected behavior. It looks like when I use UIApplicationExitsOnSuspend my app does exit memory but the app icon remains in the task window (after double tapping the home-key). I saw the icon in the task window and assumed it was still running in the background.

  • John

    Yes, it still remains in the recently opened apps list, but exits memory.

  • John

    Yes, it still remains in the recently opened apps list, but exits memory.

  • Pingback: The Best Resources In iOS Development July 12th 2010 (For Week 07/03-07/09) | iPhone iOS 4 iPad SDK Development Tutorials, Programming Tips, News

  • http://www.Vellios.com Nick Vellios

    Very cool, I am using this in my next app.

  • http://www.Vellios.com Nick Vellios

    Very cool, I am using this in my next app.

  • foobar

    This doesn't work if Xcode fails to recognise the field's type. You may have to set it manually by Ctrl-Clicking, and selecting Value Type -> Boolean.

  • http://maniacdev.com maniacdev

    Yeah, I’m not sure that multitasking really works on those other devices.. just that specific apps lend themselves to multitasking.. and many apps on iOS do not.

  • mvmmk

    Really thank you very much for the idiea:-)

  • http://twitter.com/badmonkeysoft badmonkeysoft

    Greetings, I’m using Xcode 4.1 and I cannot find that parameter. Can you show a screen shot or explain how to find it?

    Thank you for your time,
    B Monkey