O'Reilly logo

Pro Android Apps Performance Optimization by Hervé Guihot

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required