The Windows Phone operating system can take actions to reduce power consumption on the device when it detects that the user or the current application is in an idle state. Depending on the type of application you are creating, you may need to disable idle detection for users or applications. This topic explains how to modify the operating system’s idle behavior.
This Windows Phone feature has certification requirements that must be met for an application to be eligible for listing in the Windows Phone Marketplace. You should consider these requirements as you design and test your application. For more information, see Windows Phone 7 Application Certification Requirements. |
In the current release, an application is considered to be idle if the user has allowed the phone to lock. In future releases, the conditions that qualify an application as idle may change. When application idle detection is enabled, the operating system will deactivate idle applications. Disabling application idle detection requests that the operating system not perform this service. Disable application idle detection by setting the ApplicationIdleDetectionMode property of the application’s PhoneApplicationService object toDisabled. Even if application idle detection is disabled, the operating system may deactivate an application for other reasons, such as a depleted battery.
Windows Phone OS 7.1 has a number of features that that enable and improve most application scenarios that were previously addressed by disabling idle detection. For more information about these features, see the Fast Application Switching, Background Audio Agents, and Scheduled Tasks sections in Multitasking for Windows Phone.
Do not disable idle detection to speed up the resume time of your application after the phone is unlocked or to maintain the application state while the phone is locked. Applications targeted to Windows Phone OS 7.1 go into a dormant state when the lock screen engages and, when the phone unlocks, quickly resume to exactly the same state in which they entered dormancy. This is all accomplished automatically and without the drain on the battery or potential hidden data plan cost to the user that disabling idle detection introduces.
Valid reasons to disable idle detection in Windows Phone OS 7.1 applications include ones where core functionality continues while the phone is locked (for instance, an exercise tracking app) or that play back audio under lock in a fashion not supported by a background agent.
For apps targeted to Windows Phone OS 7.1. Do not disable application idle detection to speed up application resume. Doing so will not improve performance or application state maintenance, but will cause your application to drain the device battery more quickly, causing a negative user experience. Microsoft strongly recommends that any Windows Phone OS 7.0 applications that are ported to Windows Phone OS 7.1 discontinue disablement of idle detection unless the features mentioned above do not support the application’s requirements. |
If your Silverlight for Windows Phone application disables application idle detection to run under the lock screen, you should perform the following tasks to reduce your application’s power consumption while the lock screen is engaged.
Implement the Obscured event handler of the application’s root PhoneApplicationFrame object. This event is raised when the lock screen is engaged or when some other action obscures the running application’s frame, such as an incoming phone call. Perform the following steps in the Obscured event handler.
Stop all active timers using System.Threading.Timer.Dispose and DispatcherTimer.Stop.
Stop all animations by calling Storyboard.Pause or Storyboard.Stop.
Stop the accelerometer by calling Stop.
Stop the Location Service by calling Stop.
Turn off the FM radio by setting the PowerMode property to Off.
Signal your application that new network requests and isolated storage operations should not be performed.
Implement the Unobscured event handler. This event is raised when the lock screen is disengaged. In this event handler, you should restart anything that you stopped in the Obscured event handler.
If your XNA for Windows Phone game disables application idle detection to run under the lock screen, you should perform the following tasks to reduce your application’s power consumption while the lock screen is engaged.
Signal your application to return immediately from the Microsoft.Xna.Framework.Game.Update method without performing any actions.
Set the Microsoft.Xna.Framework.Game.InactiveSleepTime property to 1 second.
The following list presents important information for applications that disable idle detection.
This feature should be used with caution because applications that run while the phone is locked continue to drain the device’s battery.
If your application uses a MediaElement object, you should set its Source property to null in the Obscured event handler and then restore the previous value in theUnobscured event to ensure that the MediaElement is not consuming resources while the lock screen is engaged.
The accelerometer does not return data while the lock screen is engaged.
ApplicationIdleDetectionMode cannot be set until the PhoneApplicationFrame object has been initialized.
Always ask the user if they want to disable either UserIdleDetectionMode or ApplicationIdleDetectionMode before doing so. Your application should not assume that the user wants this behavior.
In the current release, application idle detection cannot be enabled in a single application instance after it has been disabled. Doing so throws an exception. In future releases this may be supported, so your application may choose to disable application idle detection when it is no longer needed and catch the expected exception. The following code snippet shows an implementation of this.
// Custom function to turn off idle detection. This will throw an exception in the current release.
public void TryReenableApplicationIdleDetection()
{
bool didEnable = false;
try
{
Microsoft.Phone.Shell.PhoneApplicationService.Current.ApplicationIdleDetectionMode =
Microsoft.Phone.Shell.IdleDetectionMode.Enabled;
didEnable = true;
}
catch (InvalidOperationException ex)
{
// This exception is expected in the current release.
}
// Possibly use the value of didEnable to decide what to do next.
// If it is 'true', then your app will be deactivated.
// If it is 'false', then your app will keep running.
}
Disable user idle detection by setting the UserIdleDetectionMode property of the application’s PhoneApplicationService object to Disabled. When user idle detection is enabled, the operating system will go into a low power usage state when the user is idle. Disabling this property requests that the operating system not perform this service. Use this property to disable user idle detection if your application needs to continue running even when the user is not physically interacting with the screen or hardware buttons. Example scenarios include turn-by-turn navigation applications and games that use the accelerometer for input.
This feature should be used with caution. Applications that disable user idle detection will continue to run and consume battery power when the user is not using the phone. It is recommended that applications that disable user idle detection implement their own form of idle detection and enable UserIdleDetectionMode when appropriate. For example, an accelerometer-based game could enable user idle detection if the accelerometer shows no activity for a period of time.
In the current release, the operating system considers the user to be idle when they have not touched the screen or the hardware buttons within the device lock timeout window, specified in the device’s Settings page. The conditions for detecting user idle status may change in future releases.