Search code examples
androidsocketsnetwork-programmingpush-notificationnio

Draining battery life by using the radio too much


If you've been reading my questions, you'll know that I've been having a hell of a time with this app. This app includes a push service (that I wrote from scratch) and a cloud (that I wrote from scratch.) Android reports this app is using 55% of the battery. I suspect it's because the push server isn't letting the radio sleep because it's always connected.

So my question is how can I make the radio sleep and wake up when it gets something from my server? It's using java.nio - is that a potential problem? I need the async non-blocking capabilities of it. I also do not want to use Google's Cloud Messaging Service.

Specifics: - I'm using one socket at all times that's always connected. - The client doesn't send a heartbeat (none that I wrote, anyway, nio may do it by itself) - The server only sends things when it needs to (it uses nio as well)

Thank you for any help you can provide!

Edit: The radio I'm using depends on what internet connection is available. E.G. if the user has wifi on and Android connects to a network, it'll use WiFi.


Solution

  • I figured it out! I found where the battery consumption was via socket tagging and commenting out potentially draining behaviors. I make some heavy client optimizations and the huge drain is gone. It was mainly a CPU drain due to constantly reading from the socket when it shouldn't have been.