Reader small image

You're reading from  Android High Performance Programming

Product typeBook
Published inAug 2016
Reading LevelBeginner
PublisherPackt
ISBN-139781785288951
Edition1st Edition
Languages
Tools
Right arrow
Authors (3):
Emil Atanasov
Emil Atanasov
author image
Emil Atanasov

Emil Atanasov is an IT consultant with broad experience in mobile technologies. He has been exploring the field of mobile development since 2006. Emil has a MSc in Media Informatics from RWTH Aachen University, Germany and a MSc in Computer Science from Sofia Unversity "St. Kliment Ohridsky", Bulgaria. He has worked for several huge USA companies and has been a freelancer for several years. Emil has experience in software design and development. He was involved in the process of redesigning, improving and creating a number of mobile apps. Currently, he is focused on the rapidly growing mobile sector and manages a great team of developers that provides software solutions to clients around the world. As an Android team leader and project manager, Emil was leading a team that was developing a part of the Nook Color firmware -a e-magazine/ e-book reader, which supports the proprietary Barnes & Nobel and some other e-book formats. He is one of the people behind the "Getting Started with Flurry Analytics" book. He also contributed largely to the book "Objective C Memory Management". "I want to thank my family and friends for being so cool. Thank you for supporting me even though I'm such a bizarre geeky person, who is spending most of the time in the digital world. Thank you, guys!"
Read more about Emil Atanasov

Enrique López Mañas
Enrique López Mañas
author image
Enrique López Mañas

Enrique Lpez Maas is a Google Developer Expert and independent IT consultant. He has been working with mobile technologies and learning from them since 2007. He is an avid contributor to the open source community and a FLOSS (Free Libre Open Source Software) kind of guy, being among the top 10 open source Java contributors in Germany. He is a part of the Google LaunchPad accelerator, where he participates in Google global initiatives to influence hundreds of the best startups from all around the globe. He is also a big data and machine learning aficionado. In his free time he rides his bike, take pictures, and travels until exhaustion. He also writes literature and enjoys all kinds of arts. He likes to write about himself in third person. You can follow him on Twitter (@eenriquelopez) to stay updated on his latest movements.
Read more about Enrique López Mañas

Diego Grancini
Diego Grancini
author image
Diego Grancini

Diego Grancini has a degree in telecommunications and IT engineering from Perugia University. He has developed his skills on Android development for more than six years leading and contributed to several projects, teaching and sharing his skills during his career. He joined Engineering Ingegneria Informatica S.P.A. after his degree, defining his own knowledge about Java and Android development working as the lead Android developer for years. Then he joined J.P. Morgan & Chase, strengthening his skills about security and performance in software development and Android platform in particular.
Read more about Diego Grancini

View More author details
Right arrow

Chapter 6. Networking

While talking about performance in a mobile application, the main concern is how our application behaves in poor connectivity conditions. No developer wants his users to give negative feedback because the application is too slow while uploading or downloading data, or it is not synchronized with other platforms versions of the same application. How many times do we change the networking strategy of our application because a client or users said it is too slow? Networking is not completely controllable from the client side because too many external factors are involved in the process: proxies, web servers, service providers, DNSs, and so on. We cannot know if there is a problem in one or more of the elements of that chain.

Moreover, the user does not know where the problem is, but he will think the application is not good. Then he will uninstall it. Nevertheless, we can control the application behavior and improve the user-perceived performance of our application by using...

Walkthrough


Before we get into the code, studying different techniques to improve our strategy, we want to give a general overview of networking and the possibilities the Android platform provides. So, let's think about what a client needs to do before retrieving the expected response from a server instance. When a client needs a server response, it is routed in a high-level architecture that contains many actors, such as Wi-Fi access points, LANs, proxies, servers, and DNS servers, with multiple instances of them and multiple requests to be fulfilled before getting back the desired response. Then, when the server receives the request, it needs to elaborate the response that has to be routed back to the client. The time it takes to do all of these operations needs to be reasonable for the user. Furthermore, one of the links between any two actors of the chain may be interrupted and then no response can be given back to the client. In the meantime, the user is waiting for a result on the...

Best practices


The networking theory we discussed in the previous section is the starting point for the best practices we are going to overview in the following pages. We will go through networking software architectures and patterns to follow to improve the client-server communication of our application to enhance the user's understanding of the speed of our applications.

Latency gauging

We said initially that there is no way to predict the timings for a remote request to the server. This is always true, but we can somewhat estimate its duration by tracing our requests' timings and by calculating the average value. This particular process can be helpful to define different strategies depending on latencies. For example, if the response for a particular remote resource is fast, we can expect that, in the same connectivity conditions, this will still be fast.

Moreover, we can then change the request and ask for more than in a slower response case. The classic example is image resolution: if...

Debugging tools


When in the debug phase, from the networking point of view, we need flexible tools let us test our application in different connectivity conditions, checking what we are transmitting over the network, how we are doing it, how we handle and cache responses, and if the communications are safe and secure.

In the following sections we want to discuss the new adb command introduced to support the changes inside the new Android N SDK. And, then, besides the Android tools we discussed previously in Chapter 2, Efficient Debugging, such as the Network Statistics tool and the TrafficStats API, we want to briefly introduce a couple of helpful tools. These will let us analyze the networking performance of the application and intercept the network communication to be analyzed in detail, to improve it by using the patterns we discussed earlier in this chapter.

Android N Networking ADB tool

As discussed in the previous pages, Android N introduced new restrictions on data network background...

Summary


The networking aspects of an application are the most challenging to face. Looking at the networking strategy of an application, you can find something that can be optimized from this point of view. For this purpose, we dealt with the UrlConnection API on Android to better understand what we can do with that, analyzing how we can use different network protocols, set different types of request methods, add extra parameters to requests such as headers and cookies, and handle compression in communications. Then, we went through an overview of the connection types available on the platform to know which speeds our application can reach in networking transmissions.

Then, the patterns discussed in the Best practices section are really useful when it comes to improving networking performance. The general principles to follow are:

  • Change what to transmit depending on the connectivity speed to speed up application.

  • Prefetch data to speed up navigation and reduce remote requests. It is even better...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Android High Performance Programming
Published in: Aug 2016Publisher: PacktISBN-13: 9781785288951
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (3)

author image
Emil Atanasov

Emil Atanasov is an IT consultant with broad experience in mobile technologies. He has been exploring the field of mobile development since 2006. Emil has a MSc in Media Informatics from RWTH Aachen University, Germany and a MSc in Computer Science from Sofia Unversity "St. Kliment Ohridsky", Bulgaria. He has worked for several huge USA companies and has been a freelancer for several years. Emil has experience in software design and development. He was involved in the process of redesigning, improving and creating a number of mobile apps. Currently, he is focused on the rapidly growing mobile sector and manages a great team of developers that provides software solutions to clients around the world. As an Android team leader and project manager, Emil was leading a team that was developing a part of the Nook Color firmware -a e-magazine/ e-book reader, which supports the proprietary Barnes & Nobel and some other e-book formats. He is one of the people behind the "Getting Started with Flurry Analytics" book. He also contributed largely to the book "Objective C Memory Management". "I want to thank my family and friends for being so cool. Thank you for supporting me even though I'm such a bizarre geeky person, who is spending most of the time in the digital world. Thank you, guys!"
Read more about Emil Atanasov

author image
Enrique López Mañas

Enrique Lpez Maas is a Google Developer Expert and independent IT consultant. He has been working with mobile technologies and learning from them since 2007. He is an avid contributor to the open source community and a FLOSS (Free Libre Open Source Software) kind of guy, being among the top 10 open source Java contributors in Germany. He is a part of the Google LaunchPad accelerator, where he participates in Google global initiatives to influence hundreds of the best startups from all around the globe. He is also a big data and machine learning aficionado. In his free time he rides his bike, take pictures, and travels until exhaustion. He also writes literature and enjoys all kinds of arts. He likes to write about himself in third person. You can follow him on Twitter (@eenriquelopez) to stay updated on his latest movements.
Read more about Enrique López Mañas

author image
Diego Grancini

Diego Grancini has a degree in telecommunications and IT engineering from Perugia University. He has developed his skills on Android development for more than six years leading and contributed to several projects, teaching and sharing his skills during his career. He joined Engineering Ingegneria Informatica S.P.A. after his degree, defining his own knowledge about Java and Android development working as the lead Android developer for years. Then he joined J.P. Morgan & Chase, strengthening his skills about security and performance in software development and Android platform in particular.
Read more about Diego Grancini