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.

Getting started with iPhone and iPad development, and looking for a straightforward guide to get you started with Objective-C fast as possible?
Click here to check out a great straightforward no-nonsense guide to getting started with iPhone development as fast as possible.

Share and Enjoy:
  • RSS
  • Twitter
  • Facebook
  • DZone
  • HackerNews
  • del.icio.us
  • FriendFeed

Random Posts

View Comments to “Screw Multitasking: How To Make Your iOS 4 Apps Exit For Real”

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

  • [...] wishing you could have the old school behaviour back and to Hades with this multitasking thing, here’s the trick [...]

  • [...] article that explains how to terminate your app so that it doesn’t go into suspend mode, basic [...]

  • 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.

  • 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:

    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.

  • [...] Screw Multitasking: How To Make Your iOS 4 Apps Exit For Real A quick tip on how to set your apps to remove themselves from memory immediately upon exit in iOS [...]

  • 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.

Leave a Reply

blog comments powered by Disqus