Thoughtful, detailed coverage of the Mac, iPhone, and iPad, plus the best-selling Take Control ebooks.

 

 

Pick an apple! 
 
Editing iCal Events in Snow Leopard

Snow Leopard makes looking at event details in iCal easier. In the Leopard version of iCal, you had to double-click an event to reveal only some information in a pop-up box; you then needed to click the Edit button (or press Command-E) to edit an item's information. In Snow Leopard, choose Edit > Show Inspector (or press Command-Option-I) to bring up a floating inspector that provides an editable view of any items selected in your calendar.

Submitted by
Doug McLean

 
 

What is Fast App Switching?

Send Article to a Friend

Those of you who have just used iTunes to install a shiny new iOS 4 on your iPhone or iPod touch, or who are about to obtain a shiny new iPhone 4, may find yourselves wondering about one of the touted features of this new system, fast app switching. What is fast app switching? What does it have to do with multitasking? Does it operate only through the new Home button double-press behavior? And why, for most apps, does nothing very remarkable or new seem to be happening?

Return with us now to those thrilling days of yesteryear (was it really just four months ago?), when Adam penned his provocative "Does the iPhone OS Need Multitasking?" (8 February 2010). As Adam pointed out then, in his prescient and trenchant analysis, multitasking means different things to different people. You might mean (1) what happens on Mac OS X, where multiple applications really do run simultaneously and you return from application A to a window of application B to find it in the state you left it. Or you might mean (2) the mere ability to switch rapidly between recently used applications, which save state on quitting so that they behave as if they'd remained in the state you left them. What Apple has actually implemented is something a little more ambitious than option 2, but still considerably less resource-intensive (and potentially dangerous) than option 1.

Here's the long and short of it. When you are running an app in iOS 4 and you press the Home button once to leave it, the app doesn't quit. Instead, it goes into suspended animation, like the scientists in cryogenic hibernation in "2001: A Space Odyssey." The app simply stops receiving events from the system; its run loop isn't looping. The app is both backgrounded and inert; but it is still "running," in the sense that its resources and interface are still present, so that it doesn't have to be relaunched from scratch in order to resume. That way, when you come back to that app, no matter how, the app can simply pick up doing what it was doing when you left off, instantly.

This behavior is fast app switching, and is most of what Apple calls multitasking on iOS 4. (It is not the whole of iOS 4 multitasking, because some apps with specialized functionality will register with the system to be allowed to go into suspended animation with one thread still active; such functionality is strictly limited to playing audio, location detection, and voice-over-IP. But in this article I'm not concerned with those situations.)

The fast app switching interface that you get when you double-press the Home button (a gesture also correctly predicted by Adam's article) is thus all but irrelevant to the story. Indeed, it comes as a surprise to early adopters of iOS 4.0 to realize that the fast app switching interface does not list running apps. It lists recently used apps. It's a convenient way to leave an app and launch (or resume) a different, recently used app, but it could just as well have been present back in the earliest versions of the iPhone OS. It's mere interface, the iPhone equivalent of the Mac's Command-Tab switcher. It's also a very good, very welcome interface; I wish the iPhone had worked like this all along, because switching between apps, especially between a specific pair of apps, is something I do very often. But it has nothing to do with the underlying multitasking technology of fast app switching.

You actually have no easy way to learn what apps are running (suspended). When you launch or resume an app, you can usually tell the difference between whether the app was terminated or suspended, because a terminated app will go through its launch procedure (which may involve a splash screen and other obvious clues), whereas a suspended app will just appear, instantly, right where you left it. And you have no easy way to truly quit (terminate) an app. When you leave an app, no matter how - whether you use the fast app switching interface or just single-press the Home button - the system does what it does; it isn't up to you.

Therefore, you should be wondering at this point how an app ever really quits. Surely your iPhone won't be filled with the frozen bodies of dozens of suspended apps until you reboot? There are three ways an app can be genuinely terminated:

  • The system can, at any time, terminate a suspended app (again, just like the scientists in "2001: A Space Odyssey"). It would decide to do this, not because it has gone bonkers (like HAL 9000), but because every suspended app, even though it isn't using any CPU time, is nevertheless using some memory, and memory is a limited and precious resource on a mobile device. The system reserves the right, therefore, to reclaim memory by terminating a suspended app.
  • You can terminate a suspended app manually. That's what happens if you double-press Home to enter the fast app switching interface, tap and hold on one of the four icons there to go into "shaky mode," and then tap the red delete button on any of the four icons. (If the app isn't running at all, of course, then you're just removing it from the list of recently used apps.)

  • Image
  • If an app has not been specifically recompiled for iOS 4, then when you leave it, no matter how, it is terminated.

That final point is key, especially because it contradicts everything I've said about multitasking so far. It turns out that in order to participate in multitasking and allow itself to be suspended, every app must be recompiled for iOS 4. An app that doesn't appear to behave any differently when you resume it on iOS 4 from how it behaved when you relaunched it on earlier versions of the system simply hasn't been recompiled yet. That, as a moment's reflection will show, would be the vast majority of apps!

Clearly it will take some time for developers to recompile for iOS 4 and get their updates past Apple's App Store gatekeepers and onto your device. Until they do, you won't see all that much benefit from multitasking on iOS 4. Only Apple's own apps, and those few apps that have already been updated, are acting in a new way.

Moreover, recompiling for iOS 4 is non-trivial (as I just found out while doing it for the TidBITS News app - see "Free TidBITS News iPhone App," 4 January 2010), because it will also require some rewriting. The app instantly participates in multitasking with no changes in code, merely by virtue of linking to the new iOS 4.0 frameworks - but that doesn't make it a good multitasking citizen.

One major issue is that an iOS 4-native app is notified when it is suspended, but not when it is terminated. Thus, it must do all the things to save state when it is suspended that it used to when it was terminated, just in case it later is terminated. Another issue is that the app, as it is suspended, needs to stop doing things that might cause trouble later. It must explicitly reduce its memory use if it doesn't want to be a candidate for later background termination by the system. It must cease any network activity. It may have to cancel a modal state, such as an alert that might not make sense when the user resumes later (possibly days later).

Those are all things I had to worry about when updating the TidBITS News app for iOS 4.0. Basically I had to consider every state the app might be in at the moment the user comes along and suspends it. That turned out to be remarkably difficult - and the TidBITS News app is very simple and small! Imagine, then, how long it will probably take before your favorite third-party apps are updated.

But when they are updated, you'll be switching between them with lightning speed. That's when you'll really experience fast app switching, leaving an app and coming back to it later to find it immediately ready to resume from where you left it. That's iOS 4's version of multitasking.

 

Make friends and influence people by sponsoring TidBITS!
Put your company and products in front of tens of thousands of
savvy, committed Apple users who actually buy stuff.
More information: <http://tidbits.com/advertising.html>
 

Comments about What is Fast App Switching?

Glenn Fleishman  2010-06-23 13:28
I had a slew of updates today that had notes like "fixed bugs and added multitasking."
Michael Cohen  2010-06-23 13:35
Very nice explanation, Matt, with lots of stuff that hasn't been mentioned in other descriptions of this feature.
Adam Engst  An apple icon for a TidBITS Staffer 2010-06-23 13:41
I have to say, prescient though I may have been, I really, really like the double-press on Home to access the recently used apps.
Mark H. Anbinder  An apple icon for a TidBITS Staffer 2010-06-23 22:51
I admit I really miss the customized double-press on the home button to take me to the Camera app. I've entirely stopped carrying around my Nikon Coolpix on my belt, because the iPhone 3GS camera is SO GOOD, but that means I need it to be a camera at a moment's notice. Having a Camera app that launches faster and takes pictures faster under iOS 4 is nice, but having a quick way to get to it is something I already miss... after just 36 hours.
It's not quite the same, but I put a folder in my home bar of quick use items; for me, Wikipanion, Calendar, Shazam, Weather, Calculator, Remote, and the camera app. That way, it's always right there when you're not in another app (no switching screens to get to those apps), but again, not quite the same as just instantly bringing it up to the forefront.

I'm actually in a similar boat, as I had double-click home set to bring up my favorites in the Phone app. That was how I always interacted with it (and with my contacts), so I relegated both of those apps to a lesser-used screen. Time to change my habits. :)
Matt Neuburg  An apple icon for a TidBITS Staffer 2010-06-26 09:24
Good tip!
I added my Camera to the fast apps menu. That means 1 home button press and 1 tap =)
the only problem i see with that good suggestion is that i've created folders for most of the items you mention--i have a folder with four weather apps; a folder with nine photo apps; etc. I'd surely find times when i'd turn first to the photo folder and find the camera app missing. Ideally, we'd be able to put an alias/dupe version of an app in a folder in the home bar, but there's no way to do that, right? Any suggestions?
Mark Horner  2010-06-26 10:02
Double-tap and hold
The accessibility menu has a configurable triple-click setting. If only that could be configured more generally...
I thought I was the only one, but in fact this lost functionality really and truly makes me regret upgrading. I wish there was a way to get it back!!
In what order do suspended apps get terminated? Last recently used? Using the most RAM? Combination of both?
Matt Neuburg  An apple icon for a TidBITS Staffer 2010-06-23 17:24
Basically, yes, a combination of both. Using a lot of RAM or doing other bad things in the background is a good way to get terminated. Of course you have to keep in mind that being terminated is no different than how things used to work, so it's not a huge deal. And if the user keeps launching new apps, all the older apps will probably be terminated eventually. As I said in the article, you must expect your app to be terminated while suspended; that's why you save state at suspension time.
PhilipS  2010-06-23 15:58
That's the best description I've seen yet on what it does and how it works. Thanks!
Aldo Bergamini  2010-06-24 04:40
Hi Matt,

I do have a doubt on this: "If an app has not been specifically recompiled for iOS 4, then when you quit it, it is terminated".

Apps are updated as we speak, but having had the iOS 4 for weeks now, I always saw third party apps, obviously not yet updated, sitting in the background when double clicking on the home button.

So what do you mean with this last point? Is there any change on the post GM iOS4?
Matt Neuburg  An apple icon for a TidBITS Staffer 2010-06-25 11:52
As I say in the article, what you see when you double-click the home button has nothing to do with multitasking. You see recently used apps - not only apps that are running, but all recently used apps.

You are the second person to write me who has been confused in this way, imagining that what you see when you double-click the home button is a list of running apps, so I have added language to the article to emphasize this point.
Duncan  2010-07-01 05:14
Except it does have to do with multitasking... iOS4-compatible apps that are suspended will be terminated when you delete them from the recent-apps bar. So if you see an iOS4 app in the recent-apps bar, you know you can fast-switch to it. If not, you know you can't.
Matt Neuburg  An apple icon for a TidBITS Staffer 2010-07-01 08:15
Yes, I believe that works - if you know know that the app has been recompiled for iOS 4. But you don't necessarily know that. The app's icon is not badged in some way that tells you. ("Badges?? We don't need no stinking badges!")

This reminds me of the problem I have on the iPad where I can't tell in advance whether an app will open into full screen (it's iPad-native) or into the iPhone simulator box. :)
And you can swipe the recently used apps.
Riccardo Mori  2010-06-26 05:26
It's a great article, Matt, and I took the liberty to translate it into Italian and to publish it on my blog (of course explaining that it's a translation and giving you credit).

Keep up the good work!

Cheers

Rick
Glenn Fleishman  2010-06-26 08:19
TidBITS content is all licensed under Creative Commons, so that's great. Please check the reuse terms at http://creativecommons.org/licenses/by-nc-nd/3.0/
That CC link indicates that it's under a "no derivatives" license, so it seems that making a translation would be technically disallowed, right?
Glenn Fleishman  2010-06-28 15:03
We are really broad about granting non-commercial permission when asked.
Adam Engst  An apple icon for a TidBITS Staffer 2010-06-28 15:04
Technically yes, though we're happy to grant translation permission (just did that for a Chinese blog too). There's no easy way in CC to differentiate between translations and other types of derivative works, as far as I can see.
David B  2010-06-26 09:19
Matt, this made it perfectly clear. It was honestly bothering me that I couldn't QUIT my applications. The bottom bar that appears when you double-click the home button - i used to think of that as the taskbar like on the Mac OS X. But it more of that plus "recently used apps".
Walt French  2010-06-26 10:00
When I double-click my home button to reveal the list of recently-used apps, I can press-and-hold on any app icon to start the jigglies. In this context, the app icons are tagged on the top left not with little black X's, but rather, red minuses. (I say tagged, not badged, because the badge with number of new messages still shows.)

After tapping an icon's red minus tag, it disappears from the recently-used list (and doesn't show up the next time I visit), not unlike tapping on the X to remove an app. However, the app still shows in its normal home page location. Does that mean I have found the way to actually quit an app?

(The app I tested has recently been updated but has a short startup time so I can't be sure whether the next invocation went thru startup or not.)
Matt Neuburg  An apple icon for a TidBITS Staffer 2010-06-26 10:25
I believe the article answers that question!
Walt French  2010-07-21 07:08
thank you and apologies for my thick-headedness.

But I wonder about this: MapQuest seems to be quite the battery-burner, yet once I no longer need it, I have to go thru the rather contorted click/hold-and-tap-minus approach? (Often, while driving, once I've worked my way out of an unfamiliar neighborhood.) Isn't this a bit ugly?
Adam Engst  An apple icon for a TidBITS Staffer 2010-07-21 08:22
Honestly, I'm not sure anyone quite knows the answer to this right now, and it likely varies with app. So, for instance, if you're using a background GPS app, you might want to open the app and stop navigation if you don't actually arrive at your destination, which would presumably stop it from running in the background.

That said, I've been testing the Navigon GPS app and in my experience it just terminates in the background after a little while on its own, even when it shouldn't.

So I think Apple's answer would be, "It will just work - you shouldn't have to think about quitting apps."

And I think the real-world answer will be, "Well-written apps shouldn't be a problem; others might be."
jehrler  2010-06-26 10:07
I have one very selfish question. We have a couple 3Gs that we are upgrading to iOS4.

While we know they won't "multitask", will apps that are recompiled for iOS4 be able to resume from a saved state rather than relaunch?

I know some apps were able to do this under iOS3 but will recompiling for iOS4 provide this functionality automatically for 3G owners or will it, once again, be very app specific?
Matt Neuburg  An apple icon for a TidBITS Staffer 2010-06-26 10:32
Nothing about running under or linking to a different system is going to magically change the app's code. All apps were always supposed to save state on quit and launch into that saved state, to make up for the fact that there wasn't multitasking. (The TidBITS News app does this, for example; if you were reading a story when you quit, then when you relaunch you are taken to that story again, scrolled to the same position.) If an app fails to obey this interface guideline, you should complain to the developer.
airmanchairman  2010-06-26 11:23
Insightful, concise and clear. Thanks for illuminating what promises to be exciting and productive times ahead for Apple-geeks everywhere.
Phil M  2010-06-26 15:36
This sounds exactly like Android's multitasking system, right down to the recently-used Apps menu.
Troy B  2010-06-26 16:35
"One major issue is that an iOS 4-native app is notified when it is suspended, but not when it is terminated."

This is not completely accurate. It turns out you can distinguish between a suspend event and a termination event. When an app suspends, applicationDidEnterBackground: is called on your app delegate. When an app is terminated, applicationWillTerminate: is called instead.

Check out the section titled "The Application Life Cycle" in Apple's documentation: http://bit.ly/dsMQAu
Matt Neuburg  An apple icon for a TidBITS Staffer 2010-06-26 17:20
No, what I said is exactly right. If an iOS 4-native app is suspended and then terminated (like the scientists in "2001"), applicationWillTerminate: is not called. That is why state must be saved during applicationDidEnterBackground:. It's a case of "If I should die before I wake..." Indeed, once an app is suspended, it *cannot* receive applicationWillTerminate. It can't receive *any* events while it's suspended. That's what it means to be suspended.
hapa powamoku  2010-06-26 19:56
i've been raving uselessly about this since i heard of it. i can't believe it's only a guideline! it seems like this transition is heading for a wreck as users lose all ability to know when their unsaved data & settings are safe and when not, especially w/ 256MB of RAM.

after two years of developers generally not saving states, i don't understand why apple hasn't done a matching 'fast restart' process.

and trying to use it. 3.x apps mixed w/ free interpretation of 4.x guidelines. talk about fragmentation problems!
James L  2010-06-27 00:54
What exactly is only a guideline? If it's restoring to the exact place you left when your app quit, that's reasonable. Most games should at least pause when they suspend. A secure app might reasonably lock on suspension. It's a guideline because it's good behavior for most, but not all apps.

Unsaved data and settings have nothing to do with relaunching an app in the same state as it was left. Though the latter is good practice, the safety of your data is not affected.

Also, I don't understand what you mean by fragmentation problems. Some apps will suspend, some will terminate. So what? More and more apps will be written to relaunch where they left off no matter what, as users start to demand it.

Apple has made the right choices given the hardware constraints.
hapa powamoku  2010-06-27 08:07
"Unsaved data and settings have nothing to do with relaunching an app in the same state as it was left."

if you say so. most people i think would expect those apps where it was appropriate, such as a web browser, to return to a state including data entered in a web form, if the form hadn't been submitted and the page hadn't been closed. mobile safari still now today throws away user-entered data!

this is an iphone 3GS. i wrote the paragraph above, did 'select all' & 'copy', then switched to enough other apps to really put pressure on free memory. came back to iOS4's safari and what do i see? the page is being reloaded -- the popover web form is gone, the entered text is lost.
Joshua Kaufman  2010-06-27 21:11
Thanks for this article. I have a question about quitting apps that you don't address: is there any difference between quitting an app via the fast switcher and (while the app is running) quitting via holding sleep/wake then holding the home button? The latter being the "old way" to force quit an app in iPhone OS 3.
Matt Neuburg  An apple icon for a TidBITS Staffer 2010-06-26 23:19
I don't think that ever force quit an app - it forces a shut-down of the whole device, right? If so, in that case you'd be losing any unsaved data in any running apps.
Joost van der Borg  2010-06-27 00:58
No, pressing the sleep button, then (when the shutdown slider appears) letting go and holding the home button force-quits -just- the current app. This is similar to what just holding home for 10 seconds up until 2.x would do. I'm not sure whether the running app has a chance to do anything when this happens (I would guess not).
Matt Neuburg  An apple icon for a TidBITS Staffer 2010-06-27 11:25
Wow, I never knew about that one. You have to hold the home button a really long time. Cool! Thanks for explaining that. So Joshua is right - that's a way to force termination of an app (still, on 4.0). But of course this is termination without notice, so the app has no chance to save state.
lvvvop  2010-06-27 09:28
Great article. It was recommended over at Daring Fireball and now I know about TidBITS too.
Maybe I'm showing my colours, but it seems when Apple doesn't implement some obvious feature (multitasking in this case, or more properly, fast app switching (FAS)) it's because they want to do it right within their design philosophy.
I can wait.
And another thing, I'm not sure what the turnover in apps is, but I doubt most of the 200,000+ apps will be rewritten anytime soon, that is, we're more likely to get a new version rather than an update, which makes sense, since from your experience rewriting an app to include FAS is non-trivial.
Glenn Fleishman  2010-06-27 16:50
There may be 200,000 apps available, but a good portion of those are one-trick ponies or books/guides turned into apps. The power-law curve applies to app sales as with everything else: a small portion of apps account for most sales.

I figure the most-popular apps will likely be updated quickly for at least basic fast app switching.

I'm already seeing updates with multitasking to many of the hundreds of programs I use regularly, including TomTom's navigation software (updated with background location support).
Mark Gerrior  2010-06-27 15:03
Reading this article inspired me to investigate multitasking further and post this article:
http://cli.gs/9AsaQ
Fast App Switching = System 6 Multifinder
hapa powamoku  2010-06-27 23:31
i wish
Great article - thanks. It inspired me to look at the TidBITS News app on the App Store and found that it has an average of 3 stars. So I looked at the comments all of the 13 comments give it a 4 or 5 start review. So why does the "average" show 3? (I'll guess: If the number of reviews is below some threshold, the ranking automatically stays at 3 to prevent FOB ("friends of builder") from falsely salting the results -- could that be correct?)
Glenn Fleishman  2010-06-28 11:31
There's a difference between comments and star ratings. Apple lets you give an app a star rating without leaving a comment. Notably, when you uninstall an app, you're prompted, which would be a way of capturing a lot of negative opinion (why remove an app if you like it?).
Jeff Carlson  An apple icon for a TidBITS Staffer 2010-06-28 11:32
When people delete an app from the iPhone, they're asked to rate the app, and those ratings are what contribute to the rating on the product page. It's dumb, because if someone is deleting an app it probably means they didn't like it for some reason, even if they don't write a review stating why. I think Apple removed this feature in iOS 4, but not positive.
Chris Ryland  2010-06-28 15:02
Can't you tell unequivocally if an app is being switched-to rather than restarted, if you get the little app-rotation motion?
Matt Neuburg  An apple icon for a TidBITS Staffer 2010-06-28 21:04
Nope. An app that hasn't been recompiled for iOS 4, and is incapable of doing anything but restarting from scratch, will still show up with the app-rotation motion if you launch it through the fast app switcher interface without first quitting the app you're in.
Paul Brians  2010-06-29 08:42
I've been waiting for somebody to compare this new fast-switching capability of iOS4 to the old Switcher. I remember what a miracle it seemed on my old 512 K Fat Mac in 1985.

See http://www.folklore.org/StoryView.py?story=Switcher.txt
Matt Neuburg  An apple icon for a TidBITS Staffer 2010-06-29 09:44
Adam did make that comparison in his multitasking article which I link to. That's why I don't bother repeating it.
Curious about actually quitting apps to save battery. I hear location services is a background task. If I reach my destination and am done with my TomTom app, I don't want it doing anything in the background, including wasting battery figuring out where it is. Is there a way to stop it?
Matt Neuburg  An apple icon for a TidBITS Staffer 2010-06-29 11:38
On my device, you can switch off location services in the Settings app (under General).
Oh, of course that... but I'm talking about not TOTALLY disabling Location Services. That would be an incredible pain in the a@@. If I reach my destination, switch to google maps and start walking, I want maps to know where i am, but I don't want RoadMate to be following my turn by turn GPS in the background, which I think is somthing that it is allowed to do using MultiTasking APIs.
I suppose developers need to write in a "stop" button into the program that they didn't need before. It's analogous to the iPod app. If you listened to a song, and switched to safari, the song keeps playing unless you go back and turn it off in the app. Pandora and Nav apps would just stop on Exit. Now I guess they both will have to add a UI that says "although I am now allowed to run in the background, I choose not to at this time".
Matt Neuburg  An apple icon for a TidBITS Staffer 2010-06-29 12:47
This was already a problem, as I think someone already commented. Safari and Mail already had the special ability to run in the background, and can use up your battery trying to pull down signal. What I do to prevent this is restart the device. :)

In the TidBITS News app I had to face an analogous problem: what if the user suspends me while streaming one of our podcasts? My tests suggested that this might continue in the background, and I didn't want to take a chance on that, so when the user suspends, I cancel podcast streaming. All part of being a good multitasking citizen, as I say in the article.
I don't mean to be a goof (and thanks for the great article, btw. ) but you seem to be insinuating that background processes are a bad thing.
I think that most people agree that the new limited and controlled background processes are a major new feature of iOS4. I love that Pandora will have a hook to do background processing IF I WANT IT. I love that AirSharing will be able to finish a download IF I WANT IT. I love that there are supposedly Location Services hooks for Navigation apps to continue guiding me even if I get a phone call. That's the implied beauty of MultiTasking.
I was just curious if you knew, because of your informative article, how developers and Apple will control the processes/UI so that I can be sure that my apps aren't continuing their processing WHEN I DON"T WANT THEM TO. (no shouting there, just emphasis ;-)
I thought your toolkit and developer guidelines might shed light on how Apple suggests this should be treated. iPod app has a Pause, Pandora probably will.
Matt Neuburg  An apple icon for a TidBITS Staffer 2010-07-01 08:21
"You seem to be insinuating that background processes are a bad thing." No, you're the one who wants to stop an app from using location services in the background. I'm just agreeing with you - I don't like stuff that I don't know about and that's out of my control. When I learned that Mobile Safari could be running and trying to download and draining the battery behind my back, even on iPhone 3.1.3 and before, I was sort of horrified. I think Apple should be supplying an iPhone equivalent of Activity Monitor, so users can see what's really running and how much CPU they're using, and maybe even terminate an unwanted process. But that's the opposite of Apple's philosophy ("This is an appliance, don't worry, be happy").
samsonsu  2010-06-30 10:57
Thanks for the great article.

I just upgraded my app to iOS4 and enabled fast-switching. The changes are actually quite small to make it work reasonably well:

0. Rebuild the app with iOS4. As the article pointed out, this step along enables fast-switching, though the app might not behave reasonably in all cases.

1. Save app state in applicationDidEnterBackground callback. Because the app in bg might be killed without notice, and next time it will be launched not resumed. When this happens, you still want the user to feel they return to where the left.

2. Now user can change app settings (assume you have settings.bundle) without quitting the app. App needs to register NSUserDefaultsDidChangeNotification and catch all the pref changes upon resuming. I usually register this in my viewcontroller in viewDidLoad and unregister it in viewDidUnload and dealloc.

One thing to point out: multitasking doesn't mean you don't have to save app state. App might still be killed so it's needed.
Steve Swanson  2010-06-30 15:25
So a quick question about your article--you seemed to imply that ios4-tested apps would work at least with the basic level of fast app switching but go on later to say apps need to write in the code to comply with apple's fast-app switching abilities. So far I've tried a ton of apps and only a few actually utilize the new functionality despite a ton of them being "ios 4-tested." Does this mean that developers not only need to upgrade their apps to being ios 4-tested but also need to write in code for fast-app switching for any sort of multitasking to be experience on my end? If so, why doesn't apple merely invoke a defaulted pause/save state for third party apps to allow fast app switching on every app not merely the ones that choose to do it?
Matt Neuburg  An apple icon for a TidBITS Staffer 2010-07-01 11:44
No, I say that apps that have been *recompiled* for iOS 4 work with the basic level of fast app switching.

But the App Store notice saying that an app has been *tested* with iOS 4 *doesn't* mean that the app has been recompiled for iOS 4. It means no more than it says: the app works okay in iOS 4 (according to the developer - this is just a checkbox in the app submission form).

Here's an analogy. Version 1.0 of the TidBITS News app worked fine on iPhone but not on iPad, not even in the "iPhone simulator" on the iPad (because of a bug in that simulator). We had no way of knowing that would happen, because when we wrote TidBITS News there was no such thing as an iPad - so the app had never been tested on an iPad. Once we had iPad, we saw the problem, and we worked around the problem and submitted Version 1.1 of TidBITS News. Now it works fine on iPad. But it's still not an iPad-native app; it runs in the "iPhone simulator". So now it is iPad-tested, but not iPad-native.

Some curious behavior with the iOS and state -- if I click on the link to a webpage from the Tidbits app, close and return to Tidbits, I go back to the the TidBits article and not the web page I was on (sure make sense, but also a bit confusing first time).

My comments here are as a user of the phone and not a programmer, but earlier this week got into this "state loop" as I called in:

Can't connect to 3G after sending a file
App keeps sending file
Force quit app
App returns to state of sending a file
Must manually stop file send either in outbox or by canceling upload.
Matt Neuburg  An apple icon for a TidBITS Staffer 2010-07-01 09:28
"If I click on the link to a webpage from the Tidbits app, close and return to Tidbits, I go back to the the TidBits article and not the web page I was on (sure make sense, but also a bit confusing first time)." Well, yeah, because the article was in TidBITS News but the Web page was in Safari. So if you "return to TidBITS" you go back to TidBITS News, where the article is, not Safari, where the Web page is. I don't see why that's confusing.
Because the last place I was wasn't the app, I'd left the app, but I returned to an article in the app.
Matt Neuburg  An apple icon for a TidBITS Staffer 2010-07-01 09:30
By the way, I omitted from the article a chance to blow my own trumpet here. When I wrote the TidBITS News app, I staunchly pushed back against all suggestions that I build a little Web browser into TidBITS News itself, so that clicking a link would *not* take you to Safari (you'd be able to view the Web page while staying in TidBITS News). My reasoning was partly that I couldn't possibly implement a browser as good as Safari, so you may as well just use Safari. But I also figured that some day switching between apps would be a lot faster, so this duplication of functionality would be pointless. When we release the version of TidBITS News recompiled for iOS 4, and you see what switching back and forth between TidBITS News and Safari is like, you'll be amazed and delighted - it's seamless.
Well think about what I said. You or the os is adding a step where it isn't needed. If I've clicked out of the app, that means I've gone elsewhere, but get returned to where the app last knows where I was. The problem is acerbated because in order to comment, one must leave the app. Rinse, wash, repeat if reading and commenting on articles.
So how do you exit apps that are not showing in the screen lock orintation area that are still streaming music in the background. For example MLB at bat does not let you quit it. The only way I can think of is to hold down the mlb at bat make it wiggle and delete. This is very confusing to explain to someone. Try telling your wife on how to pass apps like pandora in the background... but no MLB doesn't work that way.
im sorry if i sound stupid but i have an ipod second gen with the new update on it. when i double tap the home button it just either goes to the search or my music depending on which i have set. how can i make it open the recent app switcher you guys are talking about? thanks
Matt Neuburg  An apple icon for a TidBITS Staffer 2010-07-01 23:02
No multitasking on iPod touch 2nd gen, alas.
Simon Woodward  2010-07-05 16:25
Hi Matt, thanks for a very useful and informative article. However, it does not seem to address one significant issue (please correct me if I am wrong), that being that the 'multitasking bar' is not available if iOS4 is installed on a 3G. After upgrading my 3Gs, it was multitasking and Folders, that were our two primary reasons for upgrading our other 2 iphones, both 3G to iOS4. In doing so, both of our 3G phones have taken a speed hit, in spite of trying multiple resets and even setting up the phones as new devices. We are now hanging out for a month for a possible iOS fix from Apple, before we consider our next step.
Matt Neuburg  An apple icon for a TidBITS Staffer 2010-07-05 17:06
We covered the fact back at the start of April (http://db.tidbits.com/article/11176) that there was no multitasking on a 3G. And Apple has been very up front about it (http://www.apple.com/iphone/softwareupdate/): "multitasking is available only with iPhone 4 and iPhone 3GS". Of course the speed hit is another matter...!
Glenn Fleishman  2010-07-05 17:34
I've heard many stories that the 3G performs much worse with iOS 4. You can re-download (or find) the 3.1.3 firmware and restore it, though.
Adam Engst  An apple icon for a TidBITS Staffer 2010-07-06 12:07
Yes, Tonya's 3G (which will soon be replaced) is very poky under iOS 4. We may revert after the iPhone 4 comes and she takes over my 3GS.
Jon Rosen  2010-07-05 20:33
I'm not entirely happy with fast app switching because I end up with a large number of apps in the iPhone "dock." I wish that all apps after the most recent 5 or 10 apps used would time out and automatically terminate after a few hours. Having to terminate them manually is a pain. My iPhone 3GS is acting a lot flakier after the IOS4 upgrade. Anyway, the IOS4 upgrade for the iPad can't come soon enough for me.
Adam Engst  An apple icon for a TidBITS Staffer 2010-07-06 12:09
You really shouldn't have to terminate anything manually unless the app itself is buggy and not reloading properly when you switch to it. The fast app switcher (the "dock" as you call it) merely lists the most recently used apps; merely appearing there does not mean the app is still running (old ones won't, for instance, and the system will terminate apps whose resources it needs).
Morriz  2010-07-18 08:33
In the mean time, if you want best of both worlds, jailbreak your phone and install backgrounder. It actually sits on top of and complements the native task management.
It not only lets you override settings per app, but also adds little black and blue badge overlays telling you if an app is natively backgrounded currently (blue), or by backgrounder itself (black).

Adam Engst  An apple icon for a TidBITS Staffer 2010-07-18 11:18
Interestingly, I've started using the update to Navigon (GPS) that promises multitasking. However, after some amount of time in the background (iPod in the foreground), either the Navigon app crashes or the system terminates it. Either way, returning to it requires a fresh start.
Matt Neuburg  An apple icon for a TidBITS Staffer 2010-07-21 10:31
And Pandora just had to be updated; their initial implementation of multitasking was causing crashes in the background. Clearly, programming a multitasking app, one that runs in the background, is not easy.
please tell me the way to run an audio app in the background..what exactly should come in the application delegate methods i.e applicationDidEnterInTheBackground etc
Matt Neuburg  An apple icon for a TidBITS Staffer 2010-07-21 10:33
This isn't a technical forum; to program for iPhone, read the docs, Apple's iPhone forum, etc. Apple's free release of the videos of all the WWDC sessions has been a big help too.