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.
Important Note: |
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 shoshould consider these requirements as you design and test your application. for more information, see Windows Phone 7 Application certification requirements. |
Changing the application idle Detection Mode
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.
Changes to idle detection in Windows Phone OS 7.1
Windows Phone OS 7.1 has a number of features that enable and improve most application scenarios that were previusly 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.
important note: |
For apps targeted to Windows Phone operating system 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 stronugly 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. |
Checklist for Silverlight applications that disable application idle Detection
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 inObscuredEvent Handler.
Stop all active timers usingSystem. Threading. Timer. DisposeAndDispatchertimer. Stop.
-
Stop all animations by callingStoryboard. PauseOrStoryboard. 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 shocould not be stored med.
-
Implement the unobscured event handler. This event is raised when the lock screen is disengaged. In this event handler, you shoshould restart anything that you stopped inObscuredEvent Handler.
Checklist for xNa framework games that disable application idle Detection
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 fromMicrosoft. xNa. Framework. Game. UpdateMethod without specify Ming any actions.
SetMicrosoft. xNa. Framework. Game. inactivesleeptimeProperty to 1 second.
Other considerations when disabling application idle Detection
The following list presents important information for applications that disable idle detection.
-
This feature shocould be used with caution because applications that run while the phone is locked continue to drain the device's battery.
If your application usesMediaelementObject, you shoshould set itsSourceProperty to null inObscuredEvent handler and then restore the previous value in theunobscured event to ensure thatMediaelementIs 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 shocould 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.
Other // 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 .}
Changing the user idle Detection Mode
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 shocould 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 cocould 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.