Understanding battery optimizations
By default, all apps are subject to battery optimizations. This means:- The system restricts background execution during Doze mode
- Network access is suspended when the device is idle
- Wake locks may be ignored
- Background jobs and alarms are deferred
- Access the network during Doze mode
- Hold partial wake locks that remain effective
- Execute background work more reliably
- Receive alarms with less deferral
Checking exemption status
Always check your app’s current exemption status before requesting changes:isIgnoringBatteryOptimizations() always returns true as the concept doesn’t apply in the same way. iOS handles background execution through Background Modes configured in Xcode.Two methods for requesting exemptions
There are two approaches to guide users toward granting battery optimization exemptions:Method 1: Direct dialog (restricted)
This method shows a direct “Allow” dialog to the user:- User-friendly - single tap to approve
- Faster user experience
- Requires
REQUEST_IGNORE_BATTERY_OPTIMIZATIONSpermission - Subject to strict Google Play policy restrictions
- Can lead to app rejection if misused
Method 2: Settings list (safe)
This method opens the system’s battery optimization settings list:- Find your app in the list
- Tap on it
- Select “Don’t optimize” or “Allow”
- No special permissions required
- Safe for all apps - no Google Play restrictions
- No risk of policy violations
- Requires more user steps
- Some users may struggle to find the app in the list
Acceptable use cases
If you userequestBatteryOptimizationExemption(), your app must fall into one of these categories to comply with Google Play policies:
Chat, voice, and video apps
Apps requiring real-time messaging or calls where Firebase Cloud Messaging (FCM) high-priority messages are insufficient.
Examples: WhatsApp, Signal, Zoom
Task automation
Apps that schedule and execute automated actions, macros, or workflows on behalf of the user.
Examples: Tasker, IFTTT, automation tools
Health and fitness tracking
Apps that continuously track health metrics, workouts, or activity data in the background.
Examples: Strava, MyFitnessPal, continuous glucose monitors
Device connection and companion apps
Apps that maintain persistent connections to external devices like smartwatches, IoT devices, or medical equipment.
Examples: Wear OS companion app, smart home controllers
Personal safety apps
Apps providing emergency services, SOS features, or location tracking for personal safety.
Examples: Life360, emergency alert systems
VPN and network tools
Apps that provide VPN services, proxies, or require persistent network connections.
Examples: NordVPN, network monitoring tools
Implementation guide
Complete exemption request flow
Here’s a complete implementation that checks status, requests exemption, and handles the result:For apps with acceptable use cases
If your app qualifies for the direct dialog method:Permissions required
The library automatically includes the necessary permission in its Android manifest:REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission is not a runtime permission and doesn’t require user approval. However, its usage is monitored by Google Play’s policy enforcement.Testing exemption behavior
You can verify that battery optimization exemptions work correctly:1. Check initial state
2. Request exemption
3. Verify change after returning to app
4. Test Doze behavior
With exemption granted, test that your app works during Doze:Limitations and caveats
1. Exemption doesn’t override Power Save mode
Battery optimization exemptions only affect Doze mode. Power Save (Battery Saver) mode applies system-wide restrictions to all apps, regardless of exemption status:2. OEM restrictions still apply
Standard Android battery optimization exemptions don’t prevent OEM-specific battery management from killing your app. Manufacturers like Xiaomi, Huawei, and Samsung have additional battery optimization layers:3. User can revoke exemption
Users can manually revoke battery optimization exemptions at any time through Settings. Always check status before critical operations:4. Android version differences
Battery optimization behavior varies across Android versions:Best practices
1. Request exemptions only when necessary
Don’t request exemptions during onboarding. Wait until the user activates a feature that requires background execution:2. Provide clear user education
Always explain why you need the exemption before requesting it:3. Handle denial gracefully
If the user declines the exemption, provide degraded but functional service:4. Monitor status changes
Track exemption status throughout the app lifecycle:Related topics
- Doze and App Standby - Understand Android’s power management
- OEM Restrictions - Handle manufacturer-specific battery optimization
- Wake Locks - Keep the CPU active during background tasks

