Menu

Honor's isIgnoringBatteryOptimizations() returns true in foreground and false in background — for the same app, at the same time
🖼️

Honor's isIgnoringBatteryOptimizations() returns true in foreground and false in background — for the same app, at the same time

DEV Community·Stoyan Minchev·6 months ago
#IpgiZVob
Reading 0:00
15s threshold

I maintain an Android app that monitors elderly people and emails their family if something looks wrong. It runs a foreground service 24/7, and the single most important thing it does at install time is get added to the battery-optimisation whitelist - the one behind PowerManager.isIgnoringBatteryOptimizations() .

On my Honor device running MagicOS 9.0, I did a fresh new install. I did everything right during setup. Tapped "Don't optimise." Enabled autostart. Finished onboarding. All looked good. I opened the app a few times, closed it. Normal behavior. People will open it, see that it works, close it. They will wake up, out of curiosity, they will open it, then close it.

A few hours later, I received an email:

Battery optimisation is blocking the app. Please open Settings and set it back to "Don't optimize."

I opened the OS settings and all looked good there.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.