Android Performance Tip #1 - Apteligent

Recently our very own developer evangelist, Alex Gaber, hosted an Android Performance Best Practices webinar with Godfrey Nolan, author of “Android Best Practices” and “Decompiling Android.”

Android application development, like every other client side technology can suffer from basic performance issues. In this series of 5 blogposts, we will go through each performance tip in detail. Using a sample app we will look at tools and techniques that can be applied in each area and show how to identify areas of improvement. We use Calabash for before and after timings for each tip to keep us honest.

Tip #1: Streamline your UI

Most Android apps are some variation on a client server app. A backend server with a web service API sends information to the Android client app so it can be seen on the mobile device. In our example, the backend server is a VoIP server from Broadsoft which manages call center traffic. The majority of an Android app code is for displaying the user screens or Activities with information retrieved from the call center server via APIs.

Needless to say if you can improve the speed of your user interface then your user experiences is going to be dramatically improved.

The best tool for seeing how you app’s user interface is performing is the Hierarchy Viewer. It gives the developer an excellent picture on how long each item in your layout is behaving and how long it’s taking to display.

In this example we’re simulating what happens when an Android Developer relies too heavily on LinearLayouts when designing their app. It’s easy to design using LinearLayouts but unfortunately in anything other than the simplest of Layouts, LinearLayouts can quickly become nested and slow to draw. A more efficient way to layout your app is to use the Relative Layout, which uses less objects to draw the same layout and because it isn’t nested is much quicker to draw. Figure 1 shows the LinearLayout approach and Figure 2 shows the LinearLayout objects in the Hierarchy Viewer.


Figure 1. LinearLayout

Screen Shot 2014-06-12 at 11.02.21 AM

Figure 2. Hierarchy Viewer Linear Layout

Screen Shot 2014-06-12 at 11.03.22 AM

In even this simplest of examples we can see that there are optimization possibilities if we flatten the structure. We do this by changing from a LinearLayout to RelativeLayout, see the code changes in Figure 3 and the corresponding changes in the HierarchyView are in Figure 2.


Figure 3. RelativeLayout

Screen Shot 2014-06-12 at 2.34.13 PM

Calabash Timings
Below are some Calabash timings for the before and after for the Call Center applications Login Screen. The timings show the successful and failure login timings before and after the changes have been made. There is a 26 second improvement on the all important initial run, but otherwise the changes are in the range are in the range of 3-8 seconds in even this simplest of example.

Similar improvements were found on the other screens.  It’s also worth pointing out that the timings will be more apparent on apps with a higher degree of LinearLayout nesting.

Timings LinearLayout RelativeLayout
Run 1 3m42s 3m16s
Run 2 3m10s 3m7s
Run 3 3m16s 3m8s

Next week we will post Android Performance Tip #2. Please stay tuned!