Help / WLanguage / WLanguage functions / Standard functions / Windows functions / System functions
  • Google and disabling battery optimization
  • Required permissions
  • Requirement
  • Application in the background: Specific case from Android 10
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WindowsLinuxPHPWEBDEV - Browser code
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Stored procedures
SysBatteryOptimBackground (Function)
In french: SysOptimBatterieArrièrePlan
Used to manage battery optimization:
  • Identifies the battery optimization mode for the current application.
  • Prompts the user to disable battery optimization for a given application on the device.
This function can be used to tell the operating system to stop preventing the application from running in the background.
// If battery optimization is enabled,
// prompt the user to disable it.
IF SysBatteryOptimBackground() = sboOptimized THEN

Identifying the battery optimization mode for the current application Hide the details

<Result> = SysBatteryOptimBackground()
<Result>: Integer constant
Battery optimization status for the application:
sboNotOptimizedBattery optimization is not enabled for the application.
sboOptimizedBattery optimization is enabled for the application.

Changing the battery optimization mode for the current application Hide the details

<Mode>: Integer constant
Function call mode:
sboRequestDisableShows a system message asking the user to disable battery optimization for a given application. If battery optimization is disabled, there is no action.
sboSystemSettingsOpens the settings window containing the list of applications for which battery optimization disabled.

Google and disabling battery optimization

Google does not recommend disabling battery optimization. Most applications should not use this option. It should only be used for special cases where you need to keep full control of the application execution in the background.
Caution: On some phones, the list of non-optimized/optimized applications is not updated unless you restart the phone. This behavior has been defined by Google. However, the request to disable battery optimization does take effect: the Android settings page is the only page that may not be up to date (this can cause problems when re-enabling battery optimization).

Required permissions

The call to this function modifies the permissions required by the application.
Required permission: REQUEST_IGNORE_BATTERY_OPTIMIZATIONS: Allows the application to ask the user to disable battery optimization.
Caution: If you use this permission without good reason, Google may remove your application from the Play Store.


SysBatteryOptimBackground is available only for devices running Android 6.0 or later (API level 23)..
A fatal error occurs if the function is used with an earlier system version.
To determine the version of Android the application is running on, use SysAndroidVersion.

Application in the background: Specific case from Android 10

From Android 10, it is no longer possible to open a window when the application is in the background.
SysBatteryOptimBackground can open a window. If this function is used while the application is in the background, a fatal error will occur.
  • It is possible to determine if the application is in the background using InBackgroundMode.
  • If an application needs to interact with the user while it is in the background, the solution is to display a notification (via the Notification type). The application will be brought back to the foreground when the notification is clicked, if the ActivateApplication property is set to True. You can also open a window from the procedure passed to the ActionClick property.
Component: wd290android.aar
Minimum version required
  • Version 26
Click [Add] to post a comment

Last update: 05/26/2022

Send a report | Local help