I recently wrote about the updated story on Windows Phone and Multitasking. Yes, Windows Phone does multitask and gives developers a few options to get things done which are
- Background Audio
- Background File Transfers
- Fast Application Switching
- Scheduled Notifications
- Scheduled Tasks
I have already covered Scheduled Notifications on Windows Phone. In this article, I’ll cover Fast Application Switching or FAS. FAS essentially allows a user to quickly switch applications and not see a delay in switching apps or the ‘resuming …’ screen. When a user navigates away from your application, it will be put in a ‘dormant’ state but the application will still be held in memory. Be aware that even though you are in a dormant state, your threads, timers, web connections will stop running so essentially you can’t run any background threads while dormant. This image gives a good visual indication of what is happening
Now, the great thing is you really don’t have to do anything to implement this, as it’s automatically there if you are compiling for Mango. If your application is compiled for Windows Phone RTM or Nodo and is in Marketplace, you will have to re-compile to get Fast Application Switching. ‘Legacy’ apps will not get the ‘dormant’ state and will go straight to tombstoned as seen in this image
With FAS, as a develoepr you have to be aware that you may still get tombstoned if the device is running low on memory and the OS will tombstone the oldest app. When coming back into the Activated state, you might want to know if you have been tombstoned or not. This is pretty easy to find out using the ActivatedEventArgs.IsApplicaitonInstancePreserved as follows
<span style="color: blue;">private void </span>Application_Activated(<span style="color: blue;">object </span>sender, <span style="color: #2b91af;">ActivatedEventArgs </span>e)
<span style="color: blue;">if </span>(e.IsApplicationInstancePreserved)
<span style="color: green;">//We were dormant
<span style="color: blue;">else
<span style="color: green;">//we were tombstoned
As usual not overly complex, and that’s a good thing! If you want more details on getting ready for Fast Application Switching make sure you spend the time to watch the MIX11 session. If you are still unsure or unfamiliar with Tombstoning, read over the Execution Model Overview for Windows Phone on MSDN and play around with Visual Studio writing code.
Make sure you are prepared for this, as it will make a far better user experience for your app than the ‘resuming …’ screen!