I had a slew of updates today that had notes like "fixed bugs and added multitasking."
Very nice explanation, Matt, with lots of stuff that hasn't been mentioned in other descriptions of this feature.
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.
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. :)
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?
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?
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.
That's the best description I've seen yet on what it does and how it works. Thanks!
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?
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.
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.
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.
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!
That CC link indicates that it's under a "no derivatives" license, so it seems that making a translation would be technically disallowed, right?
We are really broad about granting non-commercial permission when asked.
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.
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".
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.)
I believe the article answers that question!
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?
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."
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?
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.
Insightful, concise and clear. Thanks for illuminating what promises to be exciting and productive times ahead for Apple-geeks everywhere.
This sounds exactly like Android's multitasking system, right down to the recently-used Apps menu.
"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
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.
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!
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.
"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.
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.
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.
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).
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.
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.
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).
Reading this article inspired me to investigate multitasking further and post this article:
Fast App Switching = System 6 Multifinder
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?)
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?).
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.
Can't you tell unequivocally if an app is being switched-to rather than restarted, if you get the little app-rotation motion?
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.
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.
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?
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".
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.
"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").
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.
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?
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.
"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.
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
No multitasking on iPod touch 2nd gen, alas.
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.
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.
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.
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.
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).
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).
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.
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
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.