Idle Detection for Windows Phone/ 系統空閑檢測

來源:互聯網
上載者:User

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 should 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 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.

 Important Note:

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.

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.

  1. 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.

  2. Stop all active timers using System.Threading.Timer.Dispose and DispatcherTimer.Stop.

  3. Stop all animations by calling Storyboard.Pause or Storyboard.Stop.

  4. Stop the accelerometer by calling Stop.

  5. Stop the Location Service by calling Stop.

  6. Turn off the FM radio by setting the PowerMode property to Off.

  7. Signal your application that new network requests and isolated storage operations should not be performed.

  8. 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.

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.

  1. Signal your application to return immediately from the Microsoft.Xna.Framework.Game.Update method without performing any actions.

  2. Set the Microsoft.Xna.Framework.Game.InactiveSleepTime property to 1 second.

Other Considerations When Disabling Application Idle Detection

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.

    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 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.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.