Google I/O 2012 - Making Good Apps Great: More Advanced Topics for Expert Android Developers

Google for Developers · 63K views · 2012 · 58:35

Open on YouTube

Software performance & optimizationSoftware practice, open source & careersWeb developmenttalkdated

Why Stack Overflow recommends it

Stack Overflow users link it whenever a question touches polling, syncing or uploading on Android, because it explains how the cell radio's power states make batched, infrequent network calls better for battery life.

Recommended by 11 people across 7 different months, 2012 to 2014.

What it is

A Google I/O 2012 session by Reto Meier, a follow-up to his 2011 talk, on turning a working Android app into a polished one. It covers efficient networking, how the cellular radio affects battery drain, less-known APIs, and testing across different screen densities.

What people said

Recommends James · 2012-06 · Stack Overflow · on “Android Sync Sqlite”

One good reason to use the Android SyncAdapter , ContentProvider and SyncManager is that you will benefit from the Google system knowledge that is useful for preserving battery life and other resources. Some of this content is in the video you link to. For example, exponential back-off logic to prevent wasteful attempts at synchronizing. There is some good info about battery life preservation by conserving cell radio power in today's Google I/O 2012 talk "Making Good Apps Great: More Advanced Topics for Expert Android Developers." [this video] While not mentioned explicitly, I think that the SyncManager is likely to have the battery conserving properties that are mentioned in this video. Based on

Recommends Alex Orlov · 2012-07 · Stack Overflow · on “Frequent http requests”

Here's a video from Google I/O exactly about this topic: Google I/O [this video] In short: Each request wakes radio from standby and turns it to full power. After request is sent it stays like this for some time and then some more time in low power state, before finally going to standby again. If you do a series of small requests, each request will trigger radio to full power and if interval between requests is too short it will never go to standby mode. But if you accumulate your requests (if your app doesn't really require to display some remote data so often) and send them as a batch but not so often it will trigger radio less and save battery life.

Recommends Eagle · 2012-07 · Stack Overflow · on “best way to implement location update service”

AlarmManager [LINK] , as mentioned by the other posts, is what you're looking for. However, It's against Android Best Practices to run things "forever, every hour" or so. If you start off by thinking "every hour, every day", you might take actions that would harm the user's battery life. Turning on gps every hour, waiting for it to acquire a lock, then turning it off, uses a lot more battery life than if you were "smarter" while checking location. If you do it right, e.g. setInexactRepeating, try to use WiFi location, set listeners for location update, then you can have your cake (long battery life for the user) and eat it too (still get the information you need). For some good tips about ho

Recommends Rawkode · 2012-07 · Stack Overflow · on “Android Device Purchase and Testing”

You should watch the Google IO 2012 talk with Reto Meier " Making Good Apps Great [this video] " as he discusses exactly this problem from about 45 minutes in. As he mentions you can't just buy devices with different sceeen sizes, as pixels are irrelevant, because of pixel density. For instance the Galaxy Nexus, One X and Nexus 7 all have the same screen resolution but in a different form factor.

Recommends Raghav Sood · 2012-08 · Stack Overflow · on “What is the power efficient way to keep offline data in sync with the server without GCM?”

A good idea would be with GCM, but as you said, that's not possible for you. In such a case, this is what I recommend: Update over WiFi if possible. This way you're likely to get the data transfer done more quickly, and hence reduce the amount of time required for the device's radios to be active. Bunch transfers together. Don't transfer say 1 file, and then wait for a bit to do another transfer. Instead, transfer right after the other. This reduces the amount of time the radios need to be active for, and hence conserves battery life Update when charging, and update more. If the device is charging, you can keep the network connection alive for longer without killing the battery. So you could

Recommends Vasile Jureschi · 2012-09 · Stack Overflow · on “Best approach to upload/sync data to server?”

For learning how to upload data I recommend watching Google I/O 2012 - Making Good Apps Great: More Advanced Topics for Expert Android Developers : [this video] from 16:43. It deals with efficiency and impact on battery life. To summarize the video: Do one large upload instead of several small uploads due to how the phone radio works, and try to minimize touching the network. On a lower level do as user370305 said, try to upload the data, if there is no connectivity delay the upload for the next time the user opens the app or clicks the upload button.

Recommends pjco · 2012-09 · Stack Overflow · on “How to run an AsyncTask every x minutes”

As Michal K said, you can use AlarmManager with a Service and/or BroadcastReceiver to wake your app periodically. However, in order to preserve the user's battery I highly recommend not polling the connection. Instead, you can use Google Cloud Messaging for Android [LINK] or GCM (formerly called C2DM) Here's the site: [LINK] EDIT The main benefit here is that Android phones that have Google accounts will already poll Google's servers periodically. They do this with cooperation from the carriers (like Verizon/AT&T). Because of this, the radio can go into low power mode and receive push notifications. By using Google's service, you enable a way for your app to receive data via push notificatio

Recommends pjco · 2012-09 · Stack Overflow · on “Android/Java: How To Stop Download After 5 Seconds?”

read() is definitely a blocking call. But I think this is a result of having to wait for the cell radio in the phone to power up to full power. One way to tell for sure would be to open a browser, surf to a page, then after the page is loaded, do your test. There was a very interesting Google IO talk this year about how the cell radio sits in an idle/low-power state most of the time, and takes a few seconds to "warm up" I'll see if I can find the link to the video. Edit: here's the video: [this video] Battery talk starts about 17:12 [this video] Ramp-up is ~2 seconds it looks like. A slide from the presentation:

Recommends CommonsWare · 2012-10 · Stack Overflow · on “Frame of reference for polling with regards to battery life?”

Let's say one of my typical polling requests consists of an empty request body (a simple GET) and a couple of hundred kilobytes in response, would a service that polls for this every 4 hours be in the category of excessive? I wouldn't think so. Every 4 minutes would be unpleasant from a battery standpoint. Ideally (IMHO), make the polling period be configurable via a preference. Also, you might wish to watch Reto Meier's Google I|O 2012 presentation [this video] , particularly the "Efficiency" section, which gets into lots of good low-level battery consumption stuff. Also also, with that payload size, IMHO battery is less of an issue than the bandwidth cost for those on pay-as-you-go plans. You'r

Recommends athor · 2012-10 · Stack Overflow · on “Recommendation/Advice for android application structure”

You should watch Reto Meier's Google IO 2012 talk - [this video] . In it he talks about mobile radios and explains why its better for battery life to fetch all your data at once. It's a great talk and worth while. Unless you have crazy amounts of data in your list views, memory shouldn't be much of a problem.