6

I am planning to write an app whose sole purpose will be to monitor the battery level, and launch an intent the moment it drops below a certain level. My one concern is that this itself will be a battery drain, and no one will want to use it.

So my question is: Exactly how much power is drained by using the ACTION_BATTERY_CHANGED broadcast receiver? Does anyone know approximately how much battery life we're talking about?

malfunction
  • 1,297
  • 2
  • 12
  • 18
  • Battery drain usually isn't the issue here. What *is* the issue is that you will need an everlasting service for this, and that's not only impractical (Android *will* stop your service eventually), but some users get peeved at applications that have services running for what, in their minds, is no good reason. – CommonsWare Jun 04 '11 at 22:52
  • @CommonsWare thanks for the (incredibly!) rapid response. So is there any way around the problem of Android eventually killing the service? – malfunction Jun 04 '11 at 23:04
  • 1
    You can use `startForeground()`, in exchange for putting an icon in the status bar, but that will annoy users even more than having the service exist in the first place. Otherwise, just return your requested restart rule from `onStartCommand()`, and deal with the fact that Android will periodically terminate and later restart your service. – CommonsWare Jun 04 '11 at 23:05
  • "Exactly how much power...?". This question is impossible to answer. Do you mean in actual milliAmps? Percentage of battery capacity? In either case this will vary from device to device due to the simple fact that efficiency of electronics is variable. – Squonk Jun 04 '11 at 23:13
  • @MisterSquonk: I guess my wording was not the best. I really just wanted a general idea of whether it would drain a significant amount of power or not. – malfunction Jun 04 '11 at 23:19

1 Answers1

5

I don't think you'll drain much power. This broadcast is sent only when level changes by one percent,

For example: 85% -> 86% or 76% -> 75%.

Android OS already tracks battery level (it has to track it in order to shutdown phone when level becomes too low, ~3-5%). So just subscribing to this broadcast shouldn't even be noticeable to the user (in terms of battery performance).

inazaruk
  • 74,247
  • 24
  • 188
  • 156