Disabling Broadcast Receivers

To preserve the battery, applications should avoid executing code that serves no purpose. In the example above, updating the TextView's text when the user interface is not in the foreground is of little value and will only draw power from the battery unnecessarily.

In addition to the ACTION_BATTERY_CHANGED sticky intent containing the battery information shown above, Android defines four more broadcast intents your application can use:

  • ACTION_BATTERY_LOW
  • ACTION_BATTERY_OKAY
  • ACTION_POWER_CONNECTED
  • ACTION_POWER_DISCONNECTED

While you could not receive the ACTION_BATTERY_CHANGED broadcast intent by simply declaring a receiver in your application's manifest (this receiver has to be registered explicitly with a call ...

Get Pro Android Apps Performance Optimization now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.