Evaluating the Impact of Android Best Practices on Energy Consumption Sona Mundody #1 , Sudarshan K *2 # Department of Computer Science, Srinivas Institute Of Technology Mangalore,India 1 sona_mdy@yahoo.com 2 krsudarshan@gmail.com Abstract—Android best practices for performance are small code changes proposed by Google to reduce execution time. This paper evaluates and analyzes the impact of two of these best practices on performance and energy consumption. The practices are applied to the code of an Android application and the code efficiency is analyzed. The practices indicate a positive impact on performance and energy consumption Keywords:Android; Best Practices; Performance; Energy Con- sumption I. I NTRODUCTION The mobile device market is rapidly developing. Most of these devices run Android Operating System. Android is a development platform for mobile applications based on Linux operating system [1] derived from an open source project led by Google. The Android application development is simplified by its SDK that provides tools and APIs needed to develop applications, favoring an easy integration with many resources available on the device. Due to limited resources available on mobile devices and the limited battery lifetime, the project of mobile apps have hard constraints specially performance and energy consumption. Many researchers have focused on evaluation of energy consumption and performance for mobile devices, focusing on hardware components or application code. The performance of C and Java was compared in [2], while a comparison between Dalvik Virtual Machine and JVM is presented in [3]. Recently, different algorithm paradigms are compared regarding performance and energy consumption in [4] and different codes for the same purpose are compared in [5]. An evaluation of the performance of the Android best practices is presented in [6]. Google presents best practices for android development focusing on performance improvement. These practices are simple tips to reduce execution time. The focus of this paper is to evaluate and analyze the impact of two of these best practices on performance and energy consumption. II. ANDROID BEST PRACTICES Google proposes several best practices [7] for performance to be incorporated in application development. According to the study conducted by Google, the use of these practices provide better overall performance in application. One of the best practices suggests that the designer must avoid the creation of unnecessary objects. Creating unnec- essary objects in application code causes periodic garbage collection and thereby creating negative impact on application performance. The other best practice indicates the use of static methods instead of virtual ones. Google claims that it brings a speed in invocation from 15% - 20%. Another practice concerns with the declaration and usage of constants and recommends the use of static final for primitive constants and strings. When using the final keyword the class no longer requires a <clinit> method because the constants go into the static field initializers in the .dex file. This makes the access faster. However, the practice is valid only to primitive types and constant Strings. Another practice suggests that the use of getters/setters methods, common in object oriented languages, should be avoided to improve Android application performance. Accord- ing to Google, the time to directly access an attribute is faster than through getter/setter methods. Concerning the manipulation of arrays, Google best prac- tices also present the suggestion about the use of appropriate for syntax. The For-each syntax, introduced by Java 1.5, can be used to manipulate collections that implement the Iterable interface and for arrays and in these cases Google suggests the use of the For-each syntax by default. However Google suggests a hand written counted loop for performance critical ArrayList iteration. The hand written counted loops are the traditional Java for syntax and can have two variations: For with length and For without length. In For without length, the array size is obtained at each iteration. This syntax is slower than the For with length, where the array size is obtained only one time before iterations, instead at each cycle. The best practices also indicate the use of package access instead private access in private inner classes. This practice is applied when an inner class needs to access the attributes of external class. The virtual machine considers the direct access of inner class to attributes of an external class as illegal, because they are different classes. Applying this practice, one