You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: uwp/debug-test-perf/optimize-background-activity.md
+10-6Lines changed: 10 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ ms.localizationpriority: medium
9
9
---
10
10
# Optimize background activity
11
11
12
-
Universal Windows apps should perform consistently well across all device families. On battery-powered devices, power consumption is a critical factor in the user's overall experience with your app. All-day battery life is a desirable feature to every user, but it requires efficiency from all of the software installed on the device, including your own.
12
+
Universal Windows apps should perform consistently well across all device families. On battery-powered devices, power consumption is a critical factor in the user's overall experience with your app. All-day battery life is a desirable feature to every user, but it requires efficiency from all of the software installed on the device, including your own.
13
13
14
14
Background task behavior is arguably the most important factor in the total energy cost of an app. A background task is any program activity that has been registered with the system to run without the app being open. See [Create and register an out-of-process background task](../launch-resume/create-and-register-a-background-task.md) for more information.
15
15
@@ -21,7 +21,7 @@ On desktop and mobile devices running Windows 10, version 1607 or later, users c
21
21
22
22
### Background permissions on mobile
23
23
24
-
On mobile devices, users will see a list of radio buttons that specify the background task permission setting for that app. Background activity can be set to "Always allowed," "Never allowed," or "Managed by Windows," which means the app's background activity is regulated by the system according to a number of factors.
24
+
On mobile devices, users will see a list of radio buttons that specify the background task permission setting for that app. Background activity can be set to "Always allowed," "Never allowed," or "Managed by Windows," which means the app's background activity is regulated by the system according to a number of factors.
25
25
26
26

27
27
@@ -35,20 +35,24 @@ On desktop devices, the "Managed by Windows" setting is presented as a toggle sw
35
35
36
36
In your app, you can use the [**BackgroundAccessStatus**](/uwp/api/windows.applicationmodel.background.backgroundaccessstatus) enum value returned by a call to the [**BackgroundExecutionManager.RequestAccessAsync()**](/uwp/api/windows.applicationmodel.background.backgroundexecutionmanager.requestaccessasync) method to determine its current background activity permission setting.
37
37
38
-
All this is to say that if your app doesn't implement responsible background activity management, the user may deny background permissions to your app altogether, which is not desirable for either party. If your app has been denied permission to run in the background but requires background activity to complete an action for the user, you can notify the user and point them to the Settings app. This can be accomplished by [Launching the Settings App](../launch-resume/launch-settings-app.md) to the Background Apps or Battery Usage Details page.
38
+
All this is to say that if your app doesn't implement responsible background activity management, the user may deny background permissions to your app altogether, which is not desirable for either party. If your app has been denied permission to run in the background but requires background activity to complete an action for the user, you can notify the user and point them to the Settings app. This can be accomplished by [Launching the Settings App](/windows/apps/develop/launch/launch-settings-app) to the Background Apps or Battery Usage Details page.
39
39
40
40
## Work with the Battery Saver feature
41
+
41
42
Battery Saver is a system-level feature that users can configure in Settings. It cuts off all background activity of all apps when the battery level drops below a user-defined threshold, *except* for the background activity of apps that have been set to "Always allowed."
42
43
43
-
Check the status of Battery Saver mode from within your app by referencing the [**PowerManager.EnergySaverStatus**](/uwp/api/windows.system.power.energysaverstatus) property. It is an enum value: either **EnergySaverStatus.Disabled**, **EnergySaverStatus.Off** or **EnergySaverStatus.On**. If your app requires background activity and is not set to "Always allowed" then it should handle **EnergySaverStatus.On** by notifying the user that the given background task(s) will not run until Battery Saver is off. While background activity management is the primary purpose of the Battery Saver feature, your app can make additional adjustments to further conserve energy when Battery Saver is on. In the case where Battery Saver is on, your app could reduce its use of animations, stop location polling, or delay syncs and backups.
44
+
Check the status of Battery Saver mode from within your app by referencing the [**PowerManager.EnergySaverStatus**](/uwp/api/windows.system.power.energysaverstatus) property. It is an enum value: either **EnergySaverStatus.Disabled**, **EnergySaverStatus.Off** or **EnergySaverStatus.On**. If your app requires background activity and is not set to "Always allowed" then it should handle **EnergySaverStatus.On** by notifying the user that the given background task(s) will not run until Battery Saver is off. While background activity management is the primary purpose of the Battery Saver feature, your app can make additional adjustments to further conserve energy when Battery Saver is on. In the case where Battery Saver is on, your app could reduce its use of animations, stop location polling, or delay syncs and backups.
44
45
45
46
## Further optimize background tasks
47
+
46
48
The following are additional steps you can take when registering your background tasks to make them more battery-aware.
47
49
48
-
### Use a maintenance trigger
50
+
### Use a maintenance trigger
51
+
49
52
A [**MaintenanceTrigger**](/uwp/api/windows.applicationmodel.background.maintenancetrigger) object can be used instead of a [**SystemTrigger**](/uwp/api/windows.applicationmodel.background.systemtrigger) object to determine when a background task starts. Tasks that use maintenance triggers will only run when the device is connected to AC power, and they are allowed to run for longer. See [Use a maintenance trigger](../launch-resume/use-a-maintenance-trigger.md) for instructions.
50
53
51
54
### Use the **BackgroundWorkCostNotHigh** system condition type
55
+
52
56
System conditions must be met in order for background tasks to run (see [Set conditions for running a background task](../launch-resume/set-conditions-for-running-a-background-task.md) for more). The background work cost is a measurement that denotes the *relative* energy impact of running the background task. A task running when the device is plugged into AC power would be marked as **low** (little/no impact on battery). A task running when the device is on battery power with the screen off is marked as **high** because there is presumably little program activity running on the device at the time, so the background task would have a greater relative cost. A task running when the device is on battery power with the screen *on* is marked as **medium**, because there is presumably already some program activity running, and the background task would add a bit more to the energy cost. The **BackgroundWorkCostNotHigh** system condition simply delays your task's ability to run until either the screen is on or the device is connected to AC power.
53
57
54
58
## Test battery efficiency
@@ -58,4 +62,4 @@ Be sure to test your app on real devices for any high-power-consumption scenario
58
62
## Related topics
59
63
60
64
*[Create and register an out-of-process background task](../launch-resume/create-and-register-a-background-task.md)
61
-
*[Planning for performance](./planning-and-measuring-performance.md)
65
+
*[Planning for performance](./planning-and-measuring-performance.md)
0 commit comments