Categories
Featured iPhone Development Resources

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.

23 replies on “Screw Multitasking: How To Make Your iOS 4 Apps Exit For Real”

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

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

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.

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.

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

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

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.

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.

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.

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.

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.