Performing background activities
As weve already discussed, developers need to think of how work that was previously done in the background can still be accomplished without impacting battery life. It is easy to ask for multitasking and just enable it, but the downside of this is that if all your apps are always running background tasks then you will never achieve long (or even improved) battery life. In a mobile and constantly connected world of laptops, this is incredibly important. So with Windows 8 and WinRT, we created new APIs to cover background processing for Metro style apps.
Again, your desktop apps will continue to run just as before, but they will also impact battery life just as they currently do (albeit with some improvements we will talk about below).
We set out to achieve a balance between enabling the kinds of rich app capability and multitasking that people expect in Windows, while also being conservative about resource utilization. To do this, we listed out a set of key scenarios we wanted to enable, and set out to achieve each of them in the most resource-efficient way possible. The result is a set of background multitasking APIs, which allow apps to complete an action in the background in a way that is resource- and power-efficient, and allow app developers to focus on what they want the app to do without having to do a bunch of extra work.
We took a scenario-focused approach to enable the most common tasks that apps would need to do in the background. Here is what we enable in the background for Metro style apps in WinRT:
Playing music
Downloading a file from or uploading it to a website
Keeping live tiles alive with fresh content
Printing
Receiving a VoIP call
Receiving an instant message
Receiving an email
Sharing content (like uploading photos to Facebook)
Synchronizing content with a tethered device (like syncing photos)
This set of scenarios is based on common patterns used by developers and common patterns we expect to see. Some of these scenarios end up using the same platform affordance, so lets walk through each of them, so you can understand the landscape and power of Windows 8:
Scenario
Description
Background download or upload
Accessing and storing content on the Internet is a pretty common scenario for apps. We want you to always have the freshest content already loaded as soon as you switch back to your app. This will be particularly helpful with magazine or news-based apps. Apps can use the new background transfer API to perform uploads and downloads in the background. This API is what we call fully brokered, which means that the OS itself performs the upload/download. This takes app code out of the picture, and helps maximize battery life.
Background audio
We still want you to be able to do more than one thing at a time, especially if one of those things is just listening to music. Any media or communications app can play audio in the background. To maximize efficiency, we suspend the app when you pause the audio.
Sharing
If your app is in the middle of sending content to a cloud service using the Share charm, it can complete that operation in the background.
Lock screen apps
Lock screen apps typically need to notify you with the latest information, and this could happen at any time, even when you are not using the app. The most common examples are your email, VoIP, and IM apps. Lock screen apps can deliver notifications and sync your data, even in the background while on battery, and even when the screen is locked.
Printing
You can print documents even though the app doing the printing has been moved to the background.
Device sync
You can synchronize content between a connected device (like a camera) and your PC even though the app is not visible on screen.
Live tiles with Windows Notification Service
Apps can give the impression they are running all of the time (even if they are suspended) by sending push notifications to your Windows 8 PC to provide the freshest content for the apps live tile.
Scheduled notifications
Apps can notify you of an event at a particular time by either updating a tile at particular time (think: calendar appointments) or by popping a notification up on the desktop reminding you to do something before you leave the office. These events are scheduled by the app, but Windows is responsible for delivering the notification, which helps minimize battery impact.
Background tasks
Apps can run code when certain events occur, such as on a periodic interval, or when you sign in to Windows or an IM service, for example. Lock screen apps can run code every 15 minutes, but non-lock screen apps can register to run code every 15 minutes as long as the device is plugged into A/C power.