I've written a simple application that displays some text and a little bit of graphics on screen. I'm using a Nexus 7, this is for an installation, and as such needs to be on continuously as much as 12 hours a day. However, despite being plugged in and charging, my application drains the battery completely in about 8 hours (10-15% / hour).

Apart from the infrequently-changing text and graphics, my application does two things:

It keeps the screen on, at full brightness (via WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); and

It opens two DatagramSockets, one to act as a UDP client, and one to act as a UDP server. These sockets are both opened automatically and managed by the library I'm using, OSCP5. It's open source, so I can hack it as needed, though the less the better. (KISS.)

I've tested the Nexus 7 battery life with no apps running, screen at full brightness, with a tickle every 29 minutes to keep it from sleeping, for a few hours with no battery drain at all. So, signs seem to point to the sockets. I don't have frequent communication on those sockets, they receive approximately a few KB every minute (based on user interaction with another part of the installation).

Is there anything I can do, specifically with the sockets, or any other general testing, to minimize or eliminate the battery drain? I only need to get through 12 hours, but keeping full charge while plugged in doesn't seem like it should be such a tall order...

有帮助吗?

解决方案

However, despite being plugged in and charging, my application drains the battery completely in about 8 hours (10-15% / hour).

What do you have the Nexus 7 plugged into? I think it can take advantage of a high-speed charging USB port, the kind you need for most tablets (Android + iPad). I could see your results being more likely if you have this plugged into a garden-variety USB port.

So, signs seem to point to the sockets.

They're certainly a candidate, though since the WiFi radio would probably say on while the device is charging anyway, I'd be a bit surprised. To me, this feels like a CPU issue, where you're busy-waiting or something rather than blocking.

Is there anything I can do, specifically with the sockets, or any other general testing, to minimize or eliminate the battery drain?

I'd see if Traceview points out where you're consuming lots of CPU time. I'd investigate the charging port issue. I'd modify your app to mock the socket work and try to see if your problem persists -- if it does, then the issue isn't the sockets.

其他提示

Well, keeping the screen on full brightness will really suck down the power. The GPS will do it too; I think those are the two biggest power sinks.

Keeping the network radios busy and keeping the cpu busy will also suck down the power. I hope you're not busy-waiting in any of your software.

Other than that, all I can suggest is that you use the high-power charger that likely came with the tablet. USB data ports are limited to 500mA current, and I've worked with more than one device that can require more than that to keep the battery alive.

Three months and endless head-desk-banging later, it turns out the culprit was my USB run. The total length is around 20'-25', and the length is attenuating the power that gets all the way through the line. Solution: powered USB hub.

So, the answer ended up having nothing to do with Android or programming at all. Sorry, SO.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top