Dealing with BroadcastReceivers on demand

A side effect of using BroadcastReceivers is that each time one of the events is actually happening, the device will wake up. This means that a small amount of energy is not to be despised if we consider the long term.

We can use an auxiliary technique here to make our application more efficient: activating or deactivating BroadcastReceivers on demand, based on the current status of the cell phone. That means: if, for example, the Internet connectivity has been lost, we might only want to wait until the Internet connection is active and dismiss the other BroadcastReceivers, since they will not be useful anymore.

The following code snippet shows how to activate or deactivate components that have been defined ...

Get Android High Performance Programming 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.