Introduction

Android quickly became almost ubiquitous. With the world transitioning from feature phones to smartphones, and then discovering that tablets are, after all, devices we can hardly live without, application developers today have a choice between mostly two platforms: Android and iOS.Android lowered, some may even say broke, the barrier of entry for application developers, because all you need to write Android applications is a computer (and of course some programming knowledge). Tools are free, and almost anyone can now write applications reaching millions of customers. With Android now spreading to a variety of devices, from tablets to televisions, it is important to make sure your applications can not only run well on all these devices but also run better than competing applications. After all, the barrier of entry was lowered for all application developers and you will in many cases find yourself competing for a slice of the ever-growing Android applications market. Whether you write applications to make a living, achieve stardom, or simply make the world a better place, performance will be one of the their key elements.

This book assumes you already have some familiarity with Android application development but want to go one step further and explore what can make your applications run faster. Although the Android tools and online documentation make it easy to create applications, performance optimization is sometimes more of an art than a science and is not documented as thoroughly. I wrote Pro Android Apps Performance Optimization to help you find easy ways to achieve good performance on virtually all Android devices, whether you are trying to optimize an existing application or are writing an application from scratch. Android allows developers to use Java, C/C++, and even assembly languages, and you can implement performance optimizations in many different ways, from taking advantage of the CPU features to simply using a different language more tailored to a specific problem.

Chapter 1 focuses on optimizing your Java code. Your first applications will most likely exclusively use the Java language, and we will see that algorithms themselves are more important than their implementation. You will also learn how to take advantage of simple techniques such as caching and minimizing memory allocations to greatly optimize your applications. In addition, you will learn how to keep your applications responsive, a very important performance indicator, and how to use databases efficiently.

Chapter 2 takes you one step further (or lower, depending on who you talk to) and introduces the Android NDK. Even though the Java code can be compiled to native code since Android 2.2, using C code to implement certain routines can yield better results. The NDK can also allow you to easily port existing code to Android without having to rewrite everything in Java.

Chapter 3 takes you to the abyss of assembly language. Albeit rarely used by most application developers, assembly language allows you to take advantage of every platform's specific instruction set and can be a great way to optimize your applications, though at the cost of increased complexity and maintenance. Though assembly code is typically limited to certain parts of an application, its benefits should not be ignored as tremendous results can be achieved thanks to carefully targeted optimizations.

Chapter 4 shows you how using less memory can improve performance. In addition to learning simple ways to use less memory in your code, you will learn how memory allocations and memory accesses have a direct impact on performance because of how CPUs are designed.

Chapter 5 teaches you how to use multi-threading in your Android applications in order to keep applications responsive and improve performance as more and more Android devices can run multiple threads simultaneously.

Chapter 6 shows you the basics of measuring your applications' performance. In addition to learning how to use the APIs to measure time, you will also learn how to use some of the Android tools to have a better view of where time is spent in your applications.

Chapter 7 teaches you how to make sure your applications use power rationally. As many Android devices are battery-powered, conserving energy is extremely important because an application that empties the battery quickly will be uninstalled quickly. This chapter shows you how to minimize power consumption without sacrificing the very things that make Android applications special.

Chapter 8 introduces some basic techniques to optimize your applications' layouts and optimize OpenGL rendering.

Chapter 9 is about RenderScript, a relatively new Android component introduced in Honeycomb. RenderScript is all about performance and has already evolved quite a bit since its first release. In this chapter you learn how to use RenderScript in your applications and also learn about the many APIs RenderScript defines.

I hope you enjoy this book and find many helpful tips in it. As you will find out, many techniques are not Androidspecific, and you will be able to re-use a lot of them on other platforms, for example iOS. Personally, I have a sweet tooth for assembly language and I hope the proliferation of the Android platform and support for assembly language in the Android NDK will entice many developers, if only to learn a new skill. However, I do want to emphasize that good design and good algorithms will often already take care of all performance optimizations you need. Good luck, and I am looking forward to your Android applications!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.84.127