Thursday, June 4, 2015

Developing for Android, IV: The Rules: Networking

Google developers are at it again with part 4 in their who knows how many part series with Developing for Android, IV: The Rules: Networking

tl;dr: One of the largest consumers of battery is network / data transmission.
  • Be stingy when and how often you get your data. 
  • Use tools like GCM, JobScheduler/GCM Network Manager. 
  • Don't ever poll. 
  • Don't sync everything.
  • Don't assume the network is up
  • Use exponential backoff when requests fail
  • Develop for the low end network - slow / packetloss. 2G networks
  • Create mobile specific APIs which return the data that the user needs. 
Expanding on these bullet points, I think one which is overlooked the most, and probably requires the most work, is having mobile specific APIs. It may be fine for your website to make 5 different requests to look up data to render on a page, but if you have a native app, tailor the API to a single call, and only return the data that is needed by the client. I don't know how many times I have seen APIs where I have to request a second API to get some little bit of data that could have been included in the first, but I have to download a 80KB json file, and parse it just to get the single field. The other recommendations are fine, and can usually be handled by the mobile engineer. Getting the resources to customize / write new APIs for mobile can be a much larger challenge. Expend your engery on it, it will make your life much easier down the line, and make your users much happier. 

No comments:

Post a Comment